← Back to all chapters

Chapter 23Down the Rabbit Hole: Merging Text Without a Server, From Fugue to Eg-walker

8 min read
rabbit-holedistributed-systemscrdtcollaboration

The number that pulled me in came from the Eg-walker paper. On one offline-heavy editing trace, textbook operational transformation took 61.1 minutes to merge two divergent histories. Eg-walker took 23.5 milliseconds on the same machine. That's a different shape of algorithm, not a constant-factor win.

So how do you merge two separately edited copies, with no server deciding who went first, and still get text a human can read?

Positions lie#

Two people hold Helo. User 1 inserts l at index 3. User 2, concurrently, appends ! at index 4. On User 1's machine the document is now Hello, and User 2's "insert at 4" lands wrong: Hell!o. The index was written against a version that no longer exists.

Operational transformation shifts indexes (4 becomes 5) by transforming each concurrent operation against the others. Google Docs does this with a central server serialising edits. But every pair of concurrent operations must be transformed, and that's where the 61 minutes come from.

Index: User 2 wrote "insert at 4" against HeloHello"!" lands here: Hell!oUser 1's insert shifted everythingID: User 2 wrote "insert after o4"H1e2l3o4!after o4same meaning on every replica
Why an index goes stale, and why an ID doesn't (schematic).

Names, not numbers#

A sequence CRDT removes the problem at the source. Every character gets a permanent ID, say H1 e2 l3 o4, and User 2's edit becomes "insert ! after o4". That means the same thing on every replica, so operations commute and replicas that saw the same operations converge.

It hides two problems:

  • Deletion. Someone may delete o4 while an offline collaborator still sends "insert after o4". So deleted characters stay as tombstones, until every replica is known to have seen the delete.
  • Ties. The nasty one.

A tie-break can shred words#

The Fugue paper's example: a list says milk; one user types eggs after it, the other bread at the same spot. "After milk" no longer names a unique place, so a deterministic rule must order them. A careless rule gives ebgrgesad. Every replica agrees on it. Nobody can read it.

This is interleaving: a readability bug, not a convergence bug, so all the correctness proofs pass.

Here's the cleanest case from the dive's simulation. Two users start from XZ. Each types a three-letter word backwards at the same spot (insert c at index 1, then b, then a), like building a list by adding at the top.

forward typing (a, b, c)
  RGA    -> XxyzabcZ   runs stay whole
  Fugue  -> XabcxyzZ   runs stay whole
backward typing (c, b, a)
  RGA    -> XxaybzcZ   INTERLEAVED
  Fugue  -> XabcxyzZ   runs stay whole
Why RGA interleaves

RGA places a new character right after its anchor, then skips any neighbour with a newer ID, so concurrent siblings end up in descending ID order:

place e after e.prev, then skip while next.id > e.id
id = (lamport_counter, replica)

Typing backwards gives every character the same anchor (X), so all six are siblings. A's IDs are (3,A) (4,A) (5,A), B's (3,B) (4,B) (5,B). Sorted descending they alternate: x a y b z c. Typing forwards anchors each character to the previous one, so it comes out fine. The rule compares IDs, never which run a character belongs to.

Fugue: make a run a subtree#

Weidner and Kleppmann's Fugue changes the data's shape: characters hang in a tree. To insert, take the character before as the left origin. If it has no right child, the new one becomes its right child. Otherwise it becomes a left child of the next element, the right origin. The document is an in-order walk, same-side siblings in ID order:

order(n) = order(L1) ++ ... ++ order(Lp) ++ [n] ++ order(Rq)

An in-order walk emits any subtree as one contiguous block. Here X already has Z as right child, so c becomes a left child of Z, b of c, a of b. Each user's word is a chain, so concurrent inserts land before or after it, never inside.

            X
                           Z
            ╱   ╲
          (A's c)   (B's z)       in-order walk:
          ╱           ╱           X  [a b c]  [x y z]  Z
       (A's b)     (B's y)
       ╱           ╱              each chain is contiguous,
    (A's a)     (B's x)           so words never interleave
Backward typing in Fugue. Each word is a left-child chain, so it is one subtree.

(Schematic: two left-child chains under Z, one per user. Tie order between the chains is by ID.)

Convergence comes free: the order depends only on the set of nodes (parent, side, ID), never arrival order.

Fugue's paper also defines "non-interleaving" precisely. The 2019 PaPoC paper that named the bug now carries errata: its definition can't be satisfied by any algorithm and its algorithm doesn't converge. Fugue's "maximal non-interleaving" is the repair, and FugueMax provably achieves it. Even the paper that named the bug had a bug.

The bill: metadata#

Nothing is ever forgotten. In the Fugue benchmark, a 105 kB document saves to 168 kB (about 60% metadata) and costs roughly 23 bytes of memory per character. Yjs saves the same document in 160 kB. Naive Fugue and FugueMax cost 618 and 685 bytes per character, which is why run-length encoding and B-trees matter more than the pseudocode. On the paper's traces, Automerge used 241 to 848 MiB of RAM while merging.

  • Document text105 kB
  • Fugue file168 kB
  • Yjs file160 kB
Saved size of the same document, kB (Fugue benchmark).

Eg-walker: keep the log, not the CRDT#

Gentle and Kleppmann's Eg-walker flips the design. Each replica stores the event graph (every edit, pointing at the edits its author had seen) and the current text as a plain string. No CRDT on disk, no per-character IDs in memory.

What Eg-walker does on a merge. Click a box.

The temporary structure tracks two states per character, and three operations move between them: apply, retreat (remove from the prepare version) and advance (add back).

s_p in {NotInsertedYet, Ins, Del 1, Del 2, ...}
s_e in {Ins, Del}

s_e: does the character exist in the latest document. s_p: did it exist at the version this event was written against, and how many deletions hit it. The count matters because two users may delete the same character; retreating one deletion must not resurrect it while the other applies.

Why it's fast: most history is a straight line. At a critical version, where every earlier event is an ancestor and every later one a descendant, nothing is concurrent, so the temporary state can be cleared. Work scales with the concurrent stretch, not the whole history.

criticalcriticalstraight:no CRDTstraight:no CRDTtemporary CRDT over concurrent editstwo users, two branches
Critical versions cut history into straight stretches (illustrative graph, not a real trace). The temporary CRDT only exists between the two diamonds.

Gentle and Kleppmann Figure 8: CPU time to merge each of seven editing traces, on a log scale, for Eg-walker, OT, a reference CRDT, Automerge and Yjs. A red line marks one 60 Hz frame. OT on trace A2 takes 61.1 minutes; Eg-walker takes 23.5 ms.

Figure 8 from Gentle and Kleppmann, "Collaborative Text Editing with Eg-walker: Better, Faster, Smaller" (EuroSys 2025), arXiv:2409.14252, licensed CC BY 4.0. Recompressed, white margins trimmed.

On the log axis, OT is competitive while history is a straight line, then falls off a cliff on real divergence: 6.3 seconds on A1, 61.1 minutes on A2. Eg-walker stays in milliseconds throughout, with steady-state memory of 432 KiB on A2. Loading is just reading cached text: 0.01 to 0.12 ms across all seven traces.

The clearing ablation

Clearing at critical versions matters on sequential traces: S1 goes from 1.8 ms with clearing to 9.8 ms without. On A2, which has no critical versions, it barely changes: 23.5 ms against 23.7 ms.

  • S1, with clearing1.8 ms
  • S1, without clearing9.8 ms
  • A2, with clearing23.5 ms
  • A2, without clearing23.7 ms
Merge time with and without clearing at critical versions, ms.

Where it still breaks#

  • Plain text only. Rich text is future work, and the critical-version cut doesn't hold for Peritext because of how it processes concurrent annotations.
  • Worst case on an adversarial graph is O(n² log n); a poor traversal order made one trace up to 8x slower.
  • The asynchronous traces were reconstructed from Git history, not recorded keystrokes, and the OT baseline is a simple textbook algorithm, not a production one.
  • Tombstones remain a problem everywhere. You can drop one only when the deletion is causally stable, and in open peer-to-peer systems you don't know every replica.
  • "Converged" isn't "correct". Two rewrites of the same sentence both survive as gibberish every replica agrees on.

The open question#

Is Eg-walker itself maximally non-interleaving? It still needs a tie-break inside its temporary state, using a Yjs-style rule. Its authors conjecture the property and leave the analysis to future work. Fugue's proof is for a tree; the Yjs-style rule orders through origins in a flat list with different invariants, so the proof doesn't carry over.

The arc as I see it: make replicas agree, make agreement readable, make it cheap. Eg-walker took a big swing at cheap. Whether it kept readable is still open, and rich text, undo and moves wait behind it.

Sources#

© 2026 Bharat Kaurav. Built with Next.js & Tailwind.

>_ bk@netherwatcheresc to close

Welcome, reader. Type help to see what this shell can do.