Skip to content

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
123456CLIENTEditor clientEDGEDocument routerSERVICEDocument ownerDATABASEPostgres op logLOG / STREAMPub/subSERVICEFan-out edgeCLIENTViewers

Select a component to see what it is responsible for and which state it owns.

  1. 1Editor client → Document router: WebSocket: ops, acks, remote ops, presence
  2. 2Document router → Document owner: Route by document id to the current owner
  3. 3Document owner → Postgres op log: Append ops at next seq (batched, epoch-fenced)
  4. 4Document owner → Pub/sub: Publish sequenced ops
  5. 5Pub/sub → Fan-out edge: Per-document subscription
  6. 6Fan-out edge → Viewers: Batched frames, bounded buffers
  • Server push
  • Request / response
  • Asynchronous

What you need to know

0 of 2 checks done
  1. 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.

  2. Work it out

    Snapshots are taken every 2,000 ops. At most how many ops does a load replay after the latest snapshot?
    ops