The problem
Real-time collaboration usually needs a central server to order edits. Offline edits then conflict. A CRDT removes the server from correctness: any copy can merge any edit, in any order.
How it works
- 01Keystroke
- 02Diff → operations
- 03Unique ids (Lamport)
- 04Broadcast
- 05Merge (RGA)
- 06Same text everywhere
What was hard
- The RGA merge rule places concurrent inserts the same way on every copy; deletes are tombstones, so late edits still find their place.
- Operations that arrive before what they depend on wait in a buffer; duplicates are ignored — so the network can reorder or repeat anything.
- Cursors are anchored to character ids, so your caret does not jump when someone types before it; emoji are never split in half.
The result
Property tests run 60 random sessions of three copies editing offline with shuffled, duplicated delivery — every one converges. Open the page in two tabs and they edit together live.