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.
- Design a collaborative offline text editor: why index-based operations diverge, and how a sequence CRDT converges whatever order operations arrive in.
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… - 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.
Start from invariants: money is neither created nor destroyed, and an operation takes effect exactly once even when the network lies. Represent amounts as… - Why does last-writer-wins by device clock lose edits, and how do hybrid logical clocks fix the ordering?
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+
- 26.1 · Designing a whole feature: the method, a messenger, an offline reader and a store
- 26.2 · Reliability, payload budgets, and analytics and experiments
- 26.3 · Multi-brand apps and SDKs for other teams
- 26.4 · RFCs and strategy, estimating, incidents and mentoring, and organisation-level bets
- 26.5 · More whole-feature designs: a feed, a video player, a map, search-as-you-type and notifications
- 26.7 · Capacity estimates and retry storms
- 26.8 · A rate limiter, push versus polling, a flight booking app, a swipe deck, an image browser, a ride-hailing rider app and a photo feed API