Chapter Twenty-Five · Problem Nineteen
Digital Wallet
Both sides of every transfer are yours, and they live apart: one commit stretched across two shards, a balance that is also a log, and a running proof that no money appeared or vanished.
"Design a digital wallet that holds balances and moves money between users instantly, at peak load of a national holiday."
On a small wallet, one transaction moves the money, and it cannot be half done. The split is what makes this hard. Once the holiday forces the accounts apart, the sender's row and the receiver's row sit on two machines, no single commit covers both, and the product has promised that nobody ever sees the money in between.
The round leans on all of Chapter 5. Why Agreement Is Hard and Transactions Across Partitions name this very problem, Leader Election and Consensus holds the decision, and Clocks and Ordering says why an account's order is a number and not a time. Chapter 3's Hot Partitions and Picking the Partition Key settle the split and the account everyone pays. Chapter 4's CAP and PACELC, Precisely names what a transfer does when a shard is gone: it refuses.
The round is pitched at staff. A senior candidate can draw the whole design, and staff is heard in the choice between three ways of moving money and in how the invariants are watched. Three things make it hard. One is a transfer across two shards, by two-phase commit, a saga, or one writer per account. Another is event sourcing: a balance as a fold over an immutable log, meaning the running total you get by going through the log in order, and a log you can replay for an audit. The last is the invariants under failure: no money created or destroyed, checked all the time.
The two chapters before this one fight other battles. Chapter 23's hotel fights over rows on one shard. Chapter 24's payment system waits on an outside party's answer. Here both sides of every transfer are yours, and nothing is unknown once your own decision is recorded, so the whole difficulty is keeping two of your own machines honest with each other.
Run a 45-minute timer and draw your own wallet first. Then test the drawing on one moment: the sender's side has committed and the receiver's has not. What does each of them see? The first ten minutes of the round are Scope, the next ten the first design, the next ten the probes, and the last fifteen go to deep dives and curveballs.