Design Google Docs
Collaborative real-time editing — OT/CRDT, presence, revision history, and permission model.
Interview tip Deep dive operational transform or CRDT for concurrent edits; WebSocket fan-out; snapshot + ops log storage.
① Functional requirements
- Rich text editing with formatting
- Multiple users edit simultaneously
- Cursor presence and selection highlights
- Revision history and restore
- Share with view/comment/edit roles
- Offline edit with sync
② Non-functional requirements
- Edit latency < 100ms perceived
- 100 collaborators per doc (practical limit)
- 99.9% availability
- No lost edits on conflict
③ Back-of-the-envelope scale
Assumptions
- 1B docs
- 10K edits/sec on hot doc
- Op log grows — compact snapshots
④ High-level architecture
Google Docs
WebSocket clients
Doc session server
OT/CRDT merge
Op log + snapshot store
⑤ Data flow & execution path
Edit propagation
Local op→Send op→Transform + apply→Broadcast ops
Snapshot every N ops
Compaction of history
⑥ API & interfaces
| Endpoint / flow | Purpose | Notes |
|---|---|---|
| WS /doc/{id} | Real-time channel | ops stream |
| GET /doc/{id} | Load snapshot | version vector |
⑦ Data model & storage
Domain-specific entities sharded by user_id or geographic key.
| Store | What | Why |
|---|---|---|
| Distributed store | Primary data | Sharded for scale |
| Kafka / Pub/Sub | Event log | Async pipelines |
| Object store | Media / blobs | GCS-style durability |
⑧ Deep dive — core components
OT vs CRDT
OT smaller ops for text; CRDT better for offline — Google uses OT-style with central server ordering.
Storage
Snapshot + append op log in Colossus/Bigtable; replay ops after snapshot for load.
⑨ Trade-offs & alternatives
| Decision | Option A | Option B | Pick when |
|---|---|---|---|
| Sync model | Central server | Peer CRDT | Central simpler permissions |
| History | Full op log | Periodic squash | Log accurate; squash saves space |
⑩ 45-minute interview script
- 0–5 min: Requirements + Google-scale assumptions
- 5–12 min: Back-of-envelope QPS and storage
- 12–22 min: Architecture diagram
- 22–35 min: Deep dive on hot path
- 35–42 min: Failure modes and trade-offs
⑪ Likely follow-up questions
| Question | Short answer |
|---|---|
| How roll out globally? | Regional cells + gradual feature rollout |
⑫ Revision checklist
- OT/CRDT mention
- WebSocket fan-out
- Presence
- Permissions
- Snapshot + log