Design a Collaborative Editor (Google Docs), stage 11 of 12: change it
History and fast loads
The op log is the source of truth, and replaying it from the start is how the owner rebuilds a document. That cost grows forever.
System so far· 7 parts
Select a component to see what it is responsible for and which state it owns.
- 1Editor client → Document router: WebSocket: ops, acks, remote ops, presence
- 2Document router → Document owner: Route by document id to the current owner
- 3Document owner → Postgres op log: Append ops at next seq (batched, epoch-fenced)
- 4Document owner → Pub/sub: Publish sequenced ops
- 5Pub/sub → Fan-out edge: Per-document subscription
- 6Fan-out edge → Viewers: Batched frames, bounded buffers
- Server push
- Request / response
- Asynchronous
What you need to know
0 of 2 checks done
When the log is the source of truth, loading a document means replaying it, and that cost grows with the document's whole life. A snapshot stores the document as it was at a given sequence number. Loading becomes: latest snapshot, then replay only the ops after it. See Append-only logs.
Work it out
Snapshots are taken every 2,000 ops. At most how many ops does a load replay after the latest snapshot?Check
Why must each snapshot record exactly which sequence number it includes?Snapshots never change once written, so they suit Object storage: keyed by
{doc}/{seq}, written once, cached forever.