26.6 · Collaborative editing, a payments ledger and clocks in sync

Three problems where being almost right is wrong: two people editing the same text, money moving exactly once, and deciding which of two writes is newer when the clocks disagree.

Mental model. Choose a representation in which the invariant is true by construction: operations that commute, integer cents with idempotency keys, and logical timestamps that respect causality.

Convergence and exactness

A text CRDT, an idempotent ledger, and hybrid logical clocks.

  1. Design a collaborative offline text editor: why index-based operations diverge, and how a sequence CRDT converges whatever order operations arrive in. 26.6.1 · L8
    Two people edit the same document, one of them offline. If an edit is “insert X at index 1”, the meaning of the index depends on what has been applied before…
  2. Design the client and ledger of a wallet or peer-to-peer payments app: integer money, idempotency keys, lost responses and an invariant you can check. 26.6.2 · L5
    Start from invariants: money is neither created nor destroyed, and an operation takes effect exactly once even when the network lies. Represent amounts as…
  3. Why does last-writer-wins by device clock lose edits, and how do hybrid logical clocks fix the ordering? 26.6.3 · L8
    Last-writer-wins (LWW) needs a total order of writes, and the obvious order is the device’s wall-clock time. Device clocks are wrong: users change them…

More in System design & staff+