Autobase: many writers, one view
Hypercore's superpower — one signed writer — is also its limit: how do five
people edit one thing? Autobase
is Holepunch's answer, and even when you do not use the library, its shape
is how you should think about multi-writer.
The idea
- Every participant writes only to their own input core (normal
single-writer Hypercores — nothing new to trust).
- Autobase interleaves all inputs into one causally ordered stream (each
entry references the latest entries the writer had seen — a vector-clock-ish
ordering, with deterministic tiebreaks).
- An apply function — pure, same on every peer — folds that stream into a
materialized view (often a Hyperbee).
const base = new Autobase(store, bootstrapKey, {
open: (store) => store.get('view'),
apply: async (nodes, view, host) => {
for (const node of nodes) {
// node.value is one writer's entry; fold it into the view.
// host.addWriter(key) is how membership changes happen — in-band.
}
}
})
await base.append({ type: 'msg', text: 'hi' }) // writes to YOUR input
Same inputs ⇒ same order ⇒ same view, on every peer. When a writer's history
arrives late, affected view state is recomputed — so apply must be
deterministic: no clocks, no randomness, no network.
When you need it (and when you don't)
p2pbuilders does not use Autobase — a board folds independent per-user logs
where cross-user ordering barely matters (votes commute; comments hang off
ids). We get convergence with a plain reducer.
Reach for Autobase when the state itself is shared and order matters: a
collaborative doc, a shared room roster, a game. That is exactly the
Storyteller: passing the pen lesson.
API details move — check https://docs.pears.com/building-blocks/autobase for
current signatures. The mental model above is stable.