Design a real-time collaborative document editor
depth · 45 min · senior/staff
Setting
You're building the real-time layer behind a collaborative document editor (Google Docs-style): multiple people type into the same document at once, and every participant's screen needs to converge to the same content, with each person's cursor visible to the others.
The ask
Design the system that lets N clients edit the same document concurrently, merges their concurrent edits correctly, and keeps everyone's view in sync in real time.
Constraints & scale
- Documents up to a few hundred pages; up to ~50 concurrent editors on a single popular document
- Two people typing in the same paragraph at the same moment must both have their changes preserved and end up with the same resulting text on every client — no silent overwrite
- A client that briefly disconnects (flaky wifi) must reconnect and catch up to the current state without re-syncing the whole document from scratch
- Keystroke-to-screen latency for the local typist must feel instant, even before the edit round-trips to the server or other clients
- The document must persist durably — a server restart must not lose in-flight edits
What a strong answer covers
Requirements → merge strategy (OT / CRDT, and why) → high-level diagram (client, real-time transport, merge/sequencing service, persistence) → 1–2 deep dives → trade-offs. Likely probes: how concurrent edits to the same region are merged deterministically, how a reconnecting client catches up cheaply, and where persistence happens without adding to typing latency.
A 45-minute plan
- 0-5 min · Requirements
- 5-10 min · Estimates/API
- 10-25 min · High-level
- 25-40 min · Deep dive
- 40-45 min · Wrap
What to cover, in order
- Requirements
- Merge strategy (OT / CRDT, and why)
- High-level diagram (client, real-time transport, merge/sequencing service, persistence)
- 1–2 deep dives
- Trade-offs
Where the follow-up questions go
Pick one of these for your deep dive before the interviewer picks for you.
- How concurrent edits to the same region are merged deterministically
- How a reconnecting client catches up cheaply
- Where persistence happens without adding to typing latency
Key trade-offs
Decisions a strong answer weighs, and what pushes each one either way.
- Operational transformation or CRDT. OT keeps documents compact and has years of production use, but needs a central server to order operations and the transform functions are famously easy to get wrong. A CRDT merges without a central authority and handles offline editing naturally, but carries per-character metadata and needs garbage collection. A server-centric product with online users leans OT; offline-first or peer-to-peer leans CRDT.
- Optimistic local apply or wait for the server. Applying your own edit immediately is what makes typing feel instant, and it means the client holds state the server has not confirmed. That forces a rebase of local pending edits whenever remote edits arrive. Waiting for a round trip is simple and unusable on a slow link.
- Operation log or periodic snapshots. Storing every operation gives history, undo and catch-up from any version, but the log grows without bound. Snapshots make loading fast and bound the log, but lose detail. Most systems keep both and compact the log behind the latest snapshot.
- Granularity of operations. Per-character operations are simple and precise, but chatty. Batching keystrokes into small groups cuts traffic and storage at the price of slightly later visibility for others. The 50-editor ceiling means this is a real cost, not just a detail.
- How strongly to persist. Durably writing every operation before acknowledging it is safest and puts storage latency on the typing path. Acknowledging from memory and persisting in small batches is fast and risks a short window of loss. Decide what a server crash is allowed to cost.
Common mistakes
What goes wrong most often on this problem, and why it hurts.
- Last write wins on a region of text. Two people typing in the same paragraph is the normal case. Overwriting one of them silently destroys work and users notice immediately.
- Naming a merge approach without showing convergence. Saying "we use a CRDT" is not an answer. You need to show why two clients that apply the same set of edits in different orders end up with the same text.
- Sending the whole document on every change. Cost grows with document length, not edit size, and a few hundred pages makes it unusable.
- Ignoring intent in position-based edits. An insert at index 40 means something different once someone else has inserted before it. Edits that are not transformed or anchored to stable identities corrupt the text.
- Forgetting cursors and presence are a separate stream. They are high frequency, ephemeral and fine to drop. Writing them to the durable log wastes storage and slows real edits.
Graded on
Requirements & scoping · Estimation · API & data model · High-level architecture · Deep dive · Scalability & performance · Reliability & consistency · Trade-offs · Operability · Communication & drive