System Design LabSystem Design QuestionsDesign Google Docs

Design Google Docs

HardReal-time Systemscollaborationreal-timewebsocketssyncversioning🔵 Google🟦 Microsoft

Question Overview

Design a real-time collaborative editor like Google Docs where many people type into the same document at once and see each other's changes instantly. The core problems are merging concurrent edits so every copy converges, ordering operations per document, and storing a replayable history.…

Sign up to see the full question and AI interviewer

Requirements

  • Concurrent rich-text editing with remote changes visible in under 200 ms at p95 in-region
  • All clients converge to identical content without losing any user's edits
  • Live cursors, selections, and presence for everyone in the document
  • Sharing with viewer, commenter, and editor roles; revocation applies to open sessions within seconds
  • Offline editing that merges cleanly with other users' changes on reconnect
  • Version history with restore; acknowledged edits are durable

Back-of-the-envelope numbers

  • Connections: 10M concurrent users ÷ ~50K WebSockets per gateway server ≈ 200 gateways, plus failover headroom
  • Edit ops at peak: 10% of connected users typing, each sending a batched op every 500 ms → 1M × 2 = 2M ops/s; ~700K ops/s averaged over the day
  • Op log: 700K ops/s × 86,400 s ≈ 60B ops/day × ~100 bytes ≈ 6 TB/day before compacting old ops into coarser revisions
  • Session servers: 6M open docs ÷ ~20K docs per server (≈ 2 GB of state at ~100 KB each) ≈ 300 servers, ~6.7K ops/s each at peak
  • Fan-out: 10M users ÷ 6M docs ≈ 1.7 per doc, so most ops reach under one other client, but a 100-editor doc turns each op into 99 sends
  • Document storage: 2B docs × 100 KB ≈ 200 TB of latest snapshots, with images kept in object storage and referenced by ID

Key components

  • Client editor: applies local ops immediately, keeps a queue of unacknowledged ops, and transforms incoming remote ops against that queue
  • Document session server: each open doc is owned by exactly one server via a lease, which orders ops, assigns revision numbers, and broadcasts them
  • OT engine: an op based on an older revision is transformed against every op committed since that revision before it is applied and broadcast
  • CRDT alternative (RGA-style sequences as in Yjs or Automerge): unique per-character IDs merge without a central orderer, at the cost of metadata and tombstones
  • Operation log plus snapshots: ops are durably appended per document before acknowledgement, with a snapshot every few hundred ops so opens replay only the tail
  • Presence channel: cursor and selection updates are ephemeral, throttled, transformed like ops, and never written to the op log
  • Permission service: ACLs checked on open and cached in the session server, with revocations pushed to evict or downgrade live sessions

Common mistakes

  • Using last-write-wins on the whole document or paragraph, which silently discards one user's concurrent edits
  • Locking paragraphs or the whole document while someone edits, which breaks the real-time collaboration requirement
  • Letting any server apply ops for the same document without a single ordering point, so copies diverge
  • Storing only the latest snapshot, which loses version history and cannot rebase edits from clients that were offline
  • Replaying the full op history on every document open instead of loading a recent snapshot plus the tail of the log
  • Persisting every cursor movement to the database even though presence is ephemeral and high-frequency
  • Acknowledging an op before it is durably written, so a session server crash loses edits users saw as saved

Likely follow-ups

  • What happens to in-flight edits when a document's session server crashes?
  • A user edits offline for a week and then reconnects; how do you merge thousands of ops safely?
  • How would you implement per-user undo in a document with many simultaneous editors?
  • How would you serve a company-wide doc with 5,000 simultaneous viewers and 50 editors?
  • How do you keep a comment anchored to a text range while that text is being edited?
  • Would you choose OT or a CRDT here, and what would change if you needed peer-to-peer sync?

No community solutions yet

Be the first to publish your solution

Practice ‘Design Google Docs’ with an AI Interviewer

Get scored feedback on your diagram, scalability approach, and trade-offs. Free while we grow — up to 3 full interviews a day.