Several people type into the same paragraph at once, and everyone must end up with exactly the same text. That convergence guarantee is the whole problem; the rest is routing every editor of a document to the same place.
Requirements. Several people edit one rich text document at once and see each other’s changes, cursors, comments and history, and offline edits merge on reconnect; remote edits appear within about 100 ms in the same region, every copy converges to the same text, and no acknowledged keystroke is lost.
Peak load
2M operations per second1M open documents × 2 editors × 1 op/s
Servers
100+about 10,000 active documents each
Operation log
about 5 TB a day50B operations × 100 B, before compaction
The design. Every editor of a document connects to the same collaboration server, routed by doc_id. The server holds the document in memory, transforms each incoming operation against the concurrent ones it already applied, assigns it the next version, appends it to the log and broadcasts it. Snapshots keep loading and history replay short. CRDTs are the alternative: a unique ID per character makes merges work in any order, which suits offline and peer to peer editing at the cost of more metadata. Cursors are presence data, broadcast and never stored.
Interview prompt
Design Google Docs: several users edit one document at the same time and see each other’s changes and cursors live.
Requirements and estimates
Functional requirements
Real time co-editing of rich text.
Collaborators’ cursors and selections.
Comments and version history.
Offline edits merge on reconnect.
Non-functional requirements
Remote edits appear within about 100 ms in the same region.
All copies converge to the same text.
No acknowledged keystroke is lost.
Estimates (assumptions)
Peak load 1M open documents × 2 editors × 1 op/s ≈ 2M operations/sServers ≈ 10,000 active documents per server ≈ 100+ collaboration serversOp log ≈ 50B ops per day × 100 B ≈ 5 TB per day before compaction
What you sketch in the first five minutes: two edits at the same moment, then the one server that puts them in order.
1. Two edits, one text
Say: concurrent edits must end as the same text on every screen.
Alice and Bob both start from “ab” at version 4182.
Alice inserts X at position 1; Bob inserts Y at position 2.
The server applies Alice’s first, then shifts Bob’s past her X: Y at 3. Both screens read “aXbY”.
Next question: why not lock the paragraph being edited? It is simpler but feels broken: people expect to type anywhere.
2. One document, one server
Say: transformation needs one place that decides the order.
Route every editor of d_71 to the same collaboration server, by doc_id.
The server gives each operation the next version and appends it to the log.
It broadcasts the operation to the other editors; snapshots keep replay short.
Next question: the server crashes. Another server claims the doc_id, loads the latest snapshot plus the operations after it, and clients reconnect.
OT or CRDT
Operational transformation (OT)
CRDT
How it converges
A server orders operations and transforms each against concurrent ones it already applied
Every character gets a unique ID; merges are commutative, so any order gives the same result
Server
Required, one authority per document
Optional; peers can sync directly
Offline editing
Possible, but long divergence is hard
Natural fit
Overhead
Small operations
More metadata: IDs per character, deletion markers
Examples
Google Docs
Yjs, Automerge, many local-first apps
One document, one server
Transformation needs a single ordering point, so every editor of a document must reach the same collaboration server. Route by doc_id with consistent hashing and a lookup service. That server holds the document in memory, assigns each operation the next version, appends it to the log, and broadcasts it. A client sends each operation with the version it was based on; if the server has moved on, it transforms the operation before applying it.
Cursors and selections are presence data: broadcast a few times per second, never persisted.
What the interviewer probes next
The server for a document crashes.
Another server claims the doc_id, loads the latest snapshot plus the operations after it, and clients reconnect. Each client resends unacknowledged operations with their base version and client operation ID, and the server transforms them and drops any it already applied.
How does version history work?
Replay operations from the nearest snapshot to reach any version. For the history panel, group operations into sessions by author and time.
Why not just lock the paragraph being edited?
It is simpler but feels broken: people expect to type anywhere. OT and CRDTs give lock-free editing.
What about very large documents?
Split them into blocks or pages, load lazily, and scope operations to blocks so a change in chapter 9 never touches chapter 1.