"Design Google Docs" is a consistency question wearing a product's clothes. Two people type into the same sentence at the same moment, on different continents, one of them on a train. Both must see their own keystrokes instantly, and a second later both must see the same document, with neither person's edit lost.
The interviewer is testing whether you know that this cannot be solved with locks (typing would stall), nor with "last write wins" (edits would vanish). The real answers, operational transformation and CRDTs, are well-known and subtle, and you are not expected to derive them. You are expected to explain why they are needed, what each costs, and how the surrounding system (ordering, storage, presence, offline) is built around them.
The vocabulary for this problem comes from consistency patterns: conflict resolution, causality and convergence. If you also need the transport for live updates, the pattern of long-lived connections is shown in Design Slack.
Clarify the requirements
Functional requirements:
- Create, open and edit a rich-text document.
- Several people edit at once, and see each other's changes and cursors live.
- Every edit is saved automatically, and a version history can be browsed and restored.
- Share with view, comment or edit permission.
- Editing continues through a short network loss and syncs afterward.
Out of scope, said aloud: spreadsheets and slides, comments and suggestions as a feature, search across documents, export formats, add-ons.
Non-functional requirements: these decide the architecture.
- Your own typing is instant. The local editor applies each keystroke at once, without waiting for the server.
- Convergence. After all edits are delivered, every client shows exactly the same document.
- Intention preservation. If you inserted a word, it stays where you meant it, even if someone else changed text around it.
- No lost edits, ever. An acknowledged edit is durable.
- Live updates in a fraction of a second for collaborators, and graceful behavior when a client goes offline.
Estimate the scale
Assume 100 million daily active users. About 20 million of them edit in a given day, producing about 1,500 operations each (keystrokes batched into small operations).
Operations: 20M × 1,500 = 30 billion a day, which is 350,000 per second on average, and about 1 million per second at peak. Expressed over all 100 million users, that is 300 operations per user per day.
Per document: the large number is spread across a very large number of documents. One document with 100 concurrent editors, each producing about 3 operations a second, handles 300 operations per second. That is easy for one server.
Storage: an operation is about 50 bytes with its metadata. 100M × 300 × 50 B × 365 = about 550 TB a year of raw operation history before compaction. Document snapshots are smaller: 2 billion documents at an average of 50 KB is 100 TB.
Loads: each user opens about 5 documents a day: 100M × 5 = 500 million loads, about 5,800 per second.
"The aggregate is large, but each document is small and independent. Nothing needs to coordinate between two documents, so we can shard by document ID. Inside one document, all that matters is a single, agreed order of operations. The hard part is not capacity, it is correctness under concurrency."
You can reproduce the operations rate and the yearly log volume in the capacity estimator.
API and data model
Editing runs over a WebSocket. Everything else is ordinary HTTP.
GET /v1/docs/{id} -> { snapshotRev, snapshot, ops[since snapshotRev] }
WS edit session:
client -> server { docId, baseRev, ops[], clientOpId }
server -> client ack { clientOpId, rev }
server -> client ops { fromRev, ops[], author }
both ways presence { cursor, selection, name }
GET /v1/docs/{id}/history?from=rev -> versionsop_log (doc_id PK, rev CK, author, ops, ts) -- append-only, the source of truth
snapshots (doc_id PK, rev CK, body_ref) -- periodic, in object storage
docs (doc_id PK, owner, acl, latest_rev)The non-obvious choice: the operation log is the truth and the document is a derived view. A snapshot is only a shortcut. That single decision gives you history, restore, crash recovery and replay for free.
High-level design
We simulate the editing path: editors connect through a WebSocket gateway to a document service, which sequences each operation, appends it to the log and keeps live session state in Redis, with snapshots written to object storage.
- The document service sequences every operation and appends it to the log before acknowledging.
- Session state lives in Redis, and periodic snapshots go to S3 so documents load quickly.
Describe this diagram
Components
- editors (Client)
- ws gateway (WebSocket gateway)
- document service (Service)
- session state (Redis)
- operation log (Cassandra)
- snapshots (Object storage (S3))
Connections
- editors sends to ws gateway
- ws gateway sends to document service
- document service sends to session state
- document service sends to operation log
- document service sends to snapshots
Run it, then try more write load or fewer log nodes. The log's write throughput is what limits how many editors a service instance can carry.
The write path: the client applies its edit locally, then sends it to the server tagged with the revision it was based on. The server transforms it against any operations it has not seen, assigns the next revision number, appends it to the log, acknowledges the sender and broadcasts to everyone else.
The load path: fetch the latest snapshot and the operations after it, and replay them. A document that has had 20,000 operations since its last snapshot would be slow to open, so snapshot every few hundred operations.
The presence path: cursors and selections are broadcast but never stored, since they are only useful for a few seconds.
The interesting problem: concurrent edits
Alice and Bob both start from the same document and edit it at the same moment. Their edits cross in the network. How do both end up with the same text?
Approach A: locks or last-writer-wins
Lock a paragraph while someone edits it, or let the most recent save replace the older one.
Good: trivially easy to reason about.
Bad: locks stall collaboration, and a client that disappears holds the lock. Last-writer-wins silently deletes someone's work whenever two people save close together. Both are unacceptable for a product whose purpose is simultaneous editing.
Approach B: operational transformation (OT) with a central server
Each edit is an operation such as Insert(index, text) or Delete(index, length). The server defines a single total order. When an operation arrives that was based on an older revision, the server transforms it against every operation that was applied in between, adjusting its position, and then applies it.
Take the document ABC. Alice inserts X at index 1 (AXBC). At the same time, Bob deletes index 2, the letter C. If Bob's operation is applied unchanged after Alice's, it would delete B instead. Transforming it against Alice's insert moves it to index 3, so both end with AXB. Clients do the same dance in reverse for operations that the server sent while their own edits were still in flight.
Good: works with a central sequencer, small operations and no metadata overhead per character. It is proven for rich text at very large scale.
Bad: the transformation functions are famously tricky to get right for every pair of operation types, and the server is a sequencer for each document, so it must be reachable.
Approach C: CRDTs
Give every character a unique, ordered identifier so that an insert means "put this character between ids P and Q". Operations commute, so replicas converge regardless of the order in which they receive them, without any central sequencer.
Good: no transformation logic, peers can sync directly, and offline editing for hours is natural.
Bad: the identifiers and the tombstones for deleted characters make the document's in-memory and stored size larger than its text, and removing that overhead needs compaction.
The recommended answer for a product like this one, with a server in the middle anyway, is B, and the reason to give is: the server already sequences operations per document, so a central order makes the transformation tractable. Say that CRDTs are the better fit when you need peer-to-peer or long offline sessions, and explain the metadata cost.
Ordering, storage and presence
One owner per document. Route all connections for a document to one document owner process, chosen by hashing the document ID with consistent hashing and held with a lease from a coordination service (see distributed coordination). The owner holds the document in memory, so transformation needs no network hops, and revisions are assigned in one place. If the owner fails, the lease expires and another loads the latest snapshot plus the log and takes over.
Durable before acknowledged. The owner appends the operation to the log (replicated) before it acknowledges or broadcasts. A crash can then never lose an acknowledged edit. Clients keep un-acknowledged operations and resend them after a reconnect, tagged with the client operation ID so duplicates are ignored.
Snapshots and history. Write a snapshot every few hundred operations or a few minutes. Version history is a view over snapshots plus the log, so "restore to yesterday" creates a new revision rather than rewriting the past.
Offline. The client queues its operations and, on reconnect, sends them with the revision they were based on. The server transforms them against everything that happened since, exactly as it does for a slow connection. Long offline gaps produce larger transformations, which is why some products limit offline editing or use CRDTs.
Bottlenecks and failures
A hot document. A document shared with an entire company and opened by 10,000 viewers is a read fan-out problem. Cap editors (for example at 100 active editors) and move viewers to a read-only broadcast path that only receives operations and does not transform.
The document owner fails. Clients detect the closed connection, reconnect to the new owner and resend any unacknowledged operations. The owner rebuilds state from snapshot and log, which takes a second or two.
Split brain on the owner. Two servers both believing they own a document would assign conflicting revisions. Use leases with fencing tokens, and make the log's append conditional on the expected revision, so the second writer's append is rejected.
What if the log store is down? The owner cannot make operations durable, so it must stop acknowledging. Clients keep editing locally and show "saving", and everything syncs when the store returns. This is the right behavior: a delayed save is recoverable, a lost acknowledged edit is not.
Trade-offs to name aloud
- OT over CRDT: compact operations and a simple storage model, in exchange for a required central sequencer and hard-to-write transformation code.
- Op log as the source of truth: perfect history and recovery, paid for with snapshots and compaction to keep loads fast.
- A single owner per document: simple ordering and fast transformation, and a brief pause during failover.
What interviewers listen for
- A working answer: WebSocket connections, a server that orders edits, a database for documents, and a mention of operational transformation or CRDTs by name.
- A strong answer: explains why locks and last-writer-wins fail, works a small transformation example, makes the operation log the source of truth with snapshots, and routes each document to one owner for ordering.
- A standout answer: also covers durable-before-ack, fencing against split brain, offline reconciliation, capping editors with a separate viewer path, ephemeral presence and the metadata cost of CRDTs.
Check your understanding
Common mistakes
Proposing locks. It is the first idea and an immediate signal that you have not thought about the product. Explain why they fail in a sentence, then move on.
Saying "use CRDTs" without costs. Name the identifier overhead and tombstones, and say when the trade is worth it.
Treating the document as the database row. If you overwrite a row on each save, history, recovery and conflict handling all become hard. Keep the log.
Letting any server handle any edit. Without one sequencing owner per document, two servers assign the same revision. Route by document and fence the owner.
Practice
A user edits offline for 30 minutes on a plane, making 2,000 operations, while a collaborator makes 800 online. How does the system reconcile them on reconnect?
Write your own answer first, on paper or in a note. Then compare.
Show a hint
Think about what the client's operations are based on, and what the server must transform them against.
Show a strong answer
The client's operations share a base. All 2,000 were created on top of the revision the client last saw, say revision R. They are sent in order, with that base revision and client operation IDs.
The server transforms against the 800. For each of the client's operations, the owner transforms it against the operations applied since revision R, then applies it. Cost is roughly the product of the two counts, 2,000 × 800 = 1.6 million pairwise transforms, which is fine for text but should be done in the owner process and in batches, with a time limit.
The client does the reverse. It transforms the server's 800 operations against its own pending ones, so its local screen converges to the same document.
Surface conflicts honestly. If both people rewrote the same paragraph, the result is correct by the rules but may read oddly. Show a "changes were merged" notice and keep history so either can restore.
The pattern worth keeping: offline editing is the same algorithm as slow editing, with a longer gap. Plan for the cost of a long gap and put a limit on it.
Opening a heavily edited document takes 8 seconds. How do you find the cause and bring it under a second?
Write your own answer first, on paper or in a note. Then compare.
Show a hint
Consider what a load does, step by step, and which step grows with history.
Show a strong answer
Measure the steps. A load reads the latest snapshot, reads the operations after it, and replays them. If the snapshot is old, the replay step dominates. Log the number of operations replayed per load.
Snapshot more often. If the document has 40,000 operations since its last snapshot, the snapshot policy is not firing for it. Snapshot by operation count as well as by time, so busy documents are covered.
The pattern worth keeping: when a derived view gets slow as history grows, bound the work with periodic checkpoints, and measure how much is replayed.
Key takeaways
- Edits are operations, and the log is the truth. The document is a derived view.
- Locks and last-writer-wins fail. Use operational transformation or a CRDT.
- A central sequencer per document makes OT tractable, and CRDTs buy peer-to-peer at the price of metadata.
- Make an operation durable before you acknowledge it.
- Shard by document, with a leased owner and fencing against split brain.
- Presence is ephemeral, and offline is the same algorithm as slow.
Further reading
- C. A. Ellis and S. J. Gibbs, "Concurrency Control in Groupware Systems", ACM SIGMOD (1989): the paper that introduced operational transformation.
- M. Shapiro et al., "Conflict-free Replicated Data Types", SSS (2011): the formal basis of CRDTs.