Case study V.12Advanced

Design a Collaborative Editor Like Google Docs

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.

The short answer

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/s
Servers    ≈ 10,000 active documents per server    ≈ 100+ collaboration servers
Op log     ≈ 50B ops per day × 100 B                ≈ 5 TB per day before compaction

Data model and operations

Data model

documents   doc_id, title, owner,
            snapshot_version
snapshots   doc_id, version, content
operations  doc_id, version, author,
            op, created_at
            append only, version + 1 each

An operation on the wire

{ "doc": "d_71", "baseVersion": 4182,
  "op": { "insert": "X", "at": 1 },
  "clientOpId": "c9-0012" }
→ { "ack": "c9-0012", "version": 4183 }

Whiteboard

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.

both start from “ab”, version 4182Alice: X at 1Bob: Y at 2serverAlice’s first, version 4183Bob’s shifted past her X: Y at 3aXbYevery screen reads “aXbY”
  1. Alice and Bob both start from “ab” at version 4182.
  2. Alice inserts X at position 1; Bob inserts Y at position 2.
  3. 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.

AliceBobLindoc_id = d_71server for d_71holds it in memorydecides the orderoperation log418141824183append onlysnapshotreplay from hereroute by doc_id: 100+ servers,about 10,000 open documents eachcursors are broadcast, never stored
  1. Route every editor of d_71 to the same collaboration server, by doc_id.
  2. The server gives each operation the next version and appends it to the log.
  3. 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 convergesA server orders operations and transforms each against concurrent ones it already appliedEvery character gets a unique ID; merges are commutative, so any order gives the same result
ServerRequired, one authority per documentOptional; peers can sync directly
Offline editingPossible, but long divergence is hardNatural fit
OverheadSmall operationsMore metadata: IDs per character, deletion markers
ExamplesGoogle DocsYjs, 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.

Building blocks used here

Want to run this as a mock interview? See interview prep.

© 2026 Arman Ajabkhani · armantik.com · Privacy