System 12.35 — Collaborative Document Editor (Google Docs)
In one line
Many people typing in the same document at once, seeing each other's changes in real time, even offline. The heart is conflict-free merging of concurrent edits with Operational Transformation or CRDTs over WebSockets.
Think of it like this
Several people editing one printed page with pencils at the same time. If Asha inserts a word at position 10 while Ravi deletes the word at position 5, Asha's position must shift to 9. Merging edits so everyone ends up with the same text is the whole problem.
Key ideas
- 01
Requirements: real-time propagation (<200 ms), convergence (everyone ends with the same document), intention preservation, offline edits that merge later, presence (cursors), version history, sharing permissions (Phase 6B, ReBAC).
- 02
OPERATIONAL TRANSFORMATION (OT): clients send operations (insert 'x' at 10); a central server orders them and TRANSFORMS each incoming op against concurrent ones already applied (shifting positions). Proven in Google Docs; needs a central sequencer per document.
- 03
CRDTs (e.g. RGA, Yjs, Automerge): every character gets a unique, ordered ID, so concurrent inserts and deletes commute and merge without a central transformer; great for offline and peer-to-peer. Costs: metadata overhead, garbage collection of tombstones.
- 04
Architecture: clients hold a WebSocket to a COLLABORATION SERVER that owns each open document (route by document ID, e.g. consistent hashing); it sequences/merges ops, broadcasts them, and appends them to an op log (Kafka/DB). Periodic SNAPSHOTS + the log give fast loading and full history. Presence (cursors) is ephemeral and sent separately (lossy is fine).
Code & diagrams
Explain without notes
OT vs CRDT: what's the key difference?
Practice
How do you scale to 10 million open documents?
Trade-offs
- ↔
Central sequencing (OT) is simpler to reason about but needs per-document ownership; CRDTs work offline but carry metadata and GC complexity.
Run it in production
You've designed it. Now build, operate, and break the same idea hands-on in the DevOps courses:
Completion checklist
I can explain convergence, OT vs CRDT, and per-document ownership