Google SD

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 opSend opTransform + applyBroadcast ops
Snapshot every N ops
Compaction of history

⑥ API & interfaces

Endpoint / flowPurposeNotes
WS /doc/{id}Real-time channelops stream
GET /doc/{id}Load snapshotversion vector

⑦ Data model & storage

Domain-specific entities sharded by user_id or geographic key.
StoreWhatWhy
Distributed storePrimary dataSharded for scale
Kafka / Pub/SubEvent logAsync pipelines
Object storeMedia / blobsGCS-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

DecisionOption AOption BPick when
Sync modelCentral serverPeer CRDTCentral simpler permissions
HistoryFull op logPeriodic squashLog accurate; squash saves space

⑩ 45-minute interview script

  1. 0–5 min: Requirements + Google-scale assumptions
  2. 5–12 min: Back-of-envelope QPS and storage
  3. 12–22 min: Architecture diagram
  4. 22–35 min: Deep dive on hot path
  5. 35–42 min: Failure modes and trade-offs

⑪ Likely follow-up questions

QuestionShort answer
How roll out globally?Regional cells + gradual feature rollout

⑫ Revision checklist

  • OT/CRDT mention
  • WebSocket fan-out
  • Presence
  • Permissions
  • Snapshot + log
googledocscollaborationwebsocket