← Lessons

quiz vs the machine

Platinum1850

System Design

Design Google Docs Collaboration

Allow many users to edit one document concurrently with consistent merged state.

7 min read · advanced · beat Platinum to climb

Requirements

  • Multiple users edit the same document at once.
  • All users converge to the same final text.
  • Edits feel instant locally and propagate quickly.

High level design

Concurrent edits are reconciled with operational transformation or conflict free replicated data types.

  • Edit model: represent each change as an operation such as insert at position or delete range.
  • Reconciliation: operational transformation rewrites incoming operations against concurrent ones so order does not matter, or a CRDT structure merges without transformation.
  • Sync server: a per document server orders operations and broadcasts them to all connected clients over websockets.

Bottlenecks

  • Convergence: naive last write wins loses edits, so transforms or CRDTs guarantee all replicas agree.
  • Connection scale: a document is pinned to one server so ordering is simple, and documents are sharded across many servers.
  • Persistence: append operations to a log and periodically snapshot to bound replay cost.

Tradeoffs

  • Operational transformation is compact but the transform logic is intricate.
  • CRDTs simplify merging but carry metadata overhead per character.

Key idea

Real time collaboration converges concurrent edits with operational transformation or CRDTs, ordered by a per document server that broadcasts operations to all clients.

Check yourself

Answer to earn rating on the learn ladder.

1. Why is plain last write wins insufficient for collaborative editing?

2. Why pin a document to a single sync server?