Collaborative editing with operational transforms and CRDTs
Updated Nov 10, 2026 · 3 min read
In a collaborative editor, everyone types into their own copy of the document, and their edits travel to everyone else. Typing has to feel instant, so nobody waits for the network before a letter appears. The hard part is that two people often edit at the same moment, and both copies still have to end up exactly the same. There are two main ways to get there, operational transforms (OT) and conflict-free replicated data types (CRDTs).
Why positions go wrong
Edits are small operations like “insert ! at position 14” or “delete 3 characters from position 4”. Positions count from the start of the document. Say Alice inserts at 14 while Bob deletes 3 characters starting at 4. On Alice’s copy, applying Bob’s delete is fine, since it comes before her insert. On Bob’s copy, the text after his delete has shifted 3 places left, so Alice’s insert at 14 lands 3 characters too far right. The copies now differ, and nobody gets an error.
Operational transforms
OT fixes this by adjusting each incoming edit for the edits that happened at the same time. Bob’s copy transforms Alice’s insert against his own delete, moving it from 14 to 11. There are rules for every pair of edit types, insert against insert, insert against delete and so on.
Getting those rules right when many people edit at once, with no one in charge, is famously hard. So practical OT systems, Google Docs among them, add a central server. It gives every edit a version number in one order. Each client sends its edit along with the version it was based on, and the server transforms it against everything accepted since that version. Every client then applies the same edits in the same order.
CRDTs
A CRDT avoids positions altogether. Every character gets a unique id, usually the author’s id plus a counter, and each insert says which character it comes after. A delete marks a character id as gone. Because edits refer to ids, not positions, they mean the same thing on every copy. Merging two copies is just combining their sets of edits, and the result is the same in any order. That’s the property that matters. No server has to decide the order.
That makes CRDTs a good fit for offline editing and for apps where devices sync directly with each other. Yjs and Automerge are popular libraries. The cost is metadata. Every character carries an id, and deleted characters often stay as markers so late edits can still find their neighbours, so a CRDT document is larger than its text. Modern libraries compress this well.
| Operational transforms | CRDTs | |
|---|---|---|
| Edits refer to | Positions | Unique character ids |
| Needs a central server | In practice, yes | No |
| Offline and peer-to-peer | Hard | Built in |
| Extra storage | Little | An id per character, plus deleted markers |
| Known for | Google Docs | Yjs, Automerge, many local-first apps |
Presence and cursors
Showing who is here and where their cursor is feels like part of the document, but it behaves very differently. A cursor position is worthless a second later. So presence travels over the same live connection as edits, throttled to a few updates a second, and lives only in the server’s memory. It never goes into the log. If an update is lost, the next one replaces it, and when someone disconnects their cursor simply disappears.
Storing a log and snapshots
The server keeps every accepted edit in an append-only log. That gives you version history for free and lets a client that reconnects ask for everything after the version it last saw. But replaying a document’s whole history every time someone opens it gets slow once it has millions of edits. So every so often the server saves a snapshot, the full document at one version. Opening a doc loads the newest snapshot and replays only the edits after it.
Snapshots cost storage. With 50-byte edits and a 50 KB snapshot every 1,000 edits, snapshots add another 50 bytes per edit, doubling the total. Teams usually keep recent snapshots plus a few older ones for version history, and trim log entries that a snapshot already covers.