Scope
Functional
- Create/edit rich-text documents; multiple users editing concurrently; live cursors.
- Comments, version history, sharing (view/comment/edit), offline editing with later merge.
Non-functional
- Local typing feels instant (< 50 ms); remote edits appear in < 300 ms.
- All replicas converge to the same document. No lost edits.
Size
- 50M DAU; ~5M documents open concurrently; most have 1 editor, some have 100+.
- Edit operations: ~10/s per active typist, batched.
The convergence problem
Alice and Bob both see "CAT". Alice inserts "S" at position 3 ("CATS"); Bob deletes position 0 ("AT"). If each simply applies the other's raw operation, Alice ends up with "ATS" but Bob inserts "S" at position 3 of "AT", which is out of range or in the wrong place. Positions must be adjusted for concurrent edits.
| Operational transformation (OT) | CRDTs | |
|---|---|---|
| Idea | Transform an incoming op against concurrent ops (shift positions) | Give every character a unique, ordered ID; merges are commutative |
| Needs a central server? | Practically yes (server orders ops) | No: peer-to-peer and offline-friendly |
| Metadata overhead | Low | Higher (IDs, tombstones), much reduced in modern libraries |
| Used by | Google Docs | Figma-like apps, Notion-style editors, Yjs and Automerge based apps |
Choice for this design: a server-ordered model (OT-style, or a CRDT with a server as the hub). The server gives a single total order, and clients rebase their pending ops on it.
The architecture
The 30-second summary
"Each open document is owned by one session server, found through a router. Clients apply edits locally, send ops with their base revision, and the server orders, transforms and appends them to an op log before broadcasting. Documents load from snapshot plus log. Cursors are ephemeral and throttled. On failover, a new owner rebuilds from storage and clients resend unacknowledged ops."
Follow-up questions the interviewer may ask
- OT or CRDTs?
- How do you scale to many documents?
- How do you handle a document with 200 simultaneous editors?
- How is version history stored?
Model answers to each of these are in the book.