← Lessons

quiz vs the machine

Platinum1780

System Design

Collaborative State Persistence

Durably storing live collaborative state without blocking editing.

6 min read · advanced · beat Platinum to climb

What must persist

A collaborative system must durably store the document so a crash never loses confirmed edits, while still serving live editing at low latency. The challenge is persisting a fast moving in memory model without stalling typing.

Snapshot plus update log

The common pattern stores a periodic snapshot of the merged state plus an append only log of updates since that snapshot. Writes append cheaply, and recovery loads the snapshot then replays the tail.

Write path tradeoffs

  • Append updates give low write latency and a complete audit trail.
  • Periodic compaction folds the log into a fresh snapshot so recovery stays fast.
  • A write ahead acknowledgement ensures an edit is durable before the client is told it is saved.

Durability must not block the hot path, so persistence runs asynchronously behind the in memory model, with the log guaranteeing nothing acknowledged is ever lost.

Key idea

Persist collaborative state as snapshots plus an append only update log, written asynchronously so durability never blocks live editing.

Check yourself

Answer to earn rating on the learn ladder.

1. What pattern balances durability with fast editing?

2. Why run persistence asynchronously behind the in memory model?

3. What does periodic compaction achieve?