A live hypermerge doc
How hypermerge kept a document
Hypermerge, from Ink & Switch, stored a shared document as a set of append-only logs, one for each writer, and let Automerge merge what they said.
The editor here is a hypermerge doc, and the columns beside it are how it is stored. Type something, then read on: each step lights up the part of the picture it explains.
Scroll to begin
One log per writer
Each writer of a doc is an actor, and each actor has a log of its own: a hypercore, which only it can append to and nobody can rewrite.
An actor is a key pair. Its public key names its log and names the actor inside Automerge. The first actor's key names the doc too: it is the id in this page's link.
Each column is one actor's log. A log only ever grows at the bottom. You get a log of your own the first time you edit.
Each edit is a change
When you pause typing, Automerge (version 0.9.2, the one hypermerge pinned) turns what you did into a change: a short list of operations, such as “insert an element after this one” and “set it to ‘h’”.
The change is appended to your log as one block. Block 0 holds your change 1, block 1 your change 2, and so on, with no gaps.
Click any block to rewind the doc to it and open the change inside.
Changes point at what they had seen
A change records the newest changes it had seen from other writers: its deps. Those are the only links between logs. The logs themselves never mention each other.
The arrows are deps, drawn from a change to what it had seen. A change also depends on the block above it in its own log; that dep is implied, so it is never written down.
Each log holds only its own changes, back to back by index, so the arrows are all that ties one log to another.
Each log is signed
A hypercore hashes its blocks into a Merkle tree: each block is a leaf, and each pair of hashes is hashed again into a parent, up to a few roots.
On every append, the actor signs the hash of those roots with its secret key. That signature is the seal under each column, checked here with the actor's public key. Anyone holding the key can tell that every block is the actor's own and in its place, and refuse one that isn't.
Your secret key stays in this browser. The app only ever sees public keys and signatures.
Any order, the same document
To open a doc, hypermerge read every actor's log and handed all the changes to Automerge, in whatever order they arrived. Automerge applies a change once everything it depends on is in, and holds it back until then.
The slider under the editor delivers the blocks one at a time. Drag it back to rewind the doc, or shuffle the blocks and press play: a change that arrives before its deps waits, outlined in amber, and the document always comes out the same.
Shuffle, then play.
Editing the past
Rewind and type. Your edit can't go into your own log, whose last block has seen the present, so it starts a new writer: a fork whose first change has seen only the blocks up to that point.
Its deps line reaches back to where you rewound. Go back to now and Automerge merges the fork with everything that came after, the same way it merges two writers working at once.
Click an earlier block or drag the slider back, type, then press “Back to now”.
Writing at the same time
Two writers never conflict over a log, because each log has one writer. Automerge merges what the logs say: edits in different places simply combine.
If two writers set the title at once, Automerge keeps one value and picks it the same way everywhere (the higher actor id wins), keeping the other as a conflict.
Add a second writer, switch one offline, edit both, then bring it back.
What yaks.app stands in for
Hypermerge sent logs between computers directly, peer to peer. Here each block is a row in this app's store on yaks.app, and every open page receives new rows as they land. The data stays as hypermerge kept it: one signed, append-only log per actor.
Send this doc's link to someone and write together.
- hypermerge on GitHub
- PushPin, the app it was built for
- Automerge 0.9.2
- hypercore