Requirements
- Multiple users edit the same document at once.
- All users converge to the same final text.
- Edits feel instant locally and propagate quickly.
High level design
Concurrent edits are reconciled with operational transformation or conflict free replicated data types.
- Edit model: represent each change as an operation such as insert at position or delete range.
- Reconciliation: operational transformation rewrites incoming operations against concurrent ones so order does not matter, or a CRDT structure merges without transformation.
- Sync server: a per document server orders operations and broadcasts them to all connected clients over websockets.
Bottlenecks
- Convergence: naive last write wins loses edits, so transforms or CRDTs guarantee all replicas agree.
- Connection scale: a document is pinned to one server so ordering is simple, and documents are sharded across many servers.
- Persistence: append operations to a log and periodically snapshot to bound replay cost.
Tradeoffs
- Operational transformation is compact but the transform logic is intricate.
- CRDTs simplify merging but carry metadata overhead per character.
Key idea
Real time collaboration converges concurrent edits with operational transformation or CRDTs, ordered by a per document server that broadcasts operations to all clients.