Lesson 1 · Minutes 0-10

Digital Wallet: Scope

Problem

Two words in the question carry the whole problem, and neither means anything yet. "Instantly" has to become a rule about what people may see, and "a national holiday" has to become a number. The first ten minutes turn them into both, and end with the API.

Five Questions, and What Each One Moves

Each of these changes what you draw, so each comes with the answer this lesson agrees and what it moves.

  1. How many accounts and transfers, and how high is the holiday? This sets whether one store can hold it. Agreed: 50 million accounts, merchants among them; 100 million transfers on an ordinary day; and a holiday's busiest minute at twenty times the ordinary average.
  2. May anyone ever see a transfer half done? This picks the protocol. Agreed: no. Instantly means both people see the result together, under a second, and the app has no pending state. A yes would reopen the saga, the step-by-step alternative the last lesson weighs.
  3. Can a balance go below zero? A floor has to be checked as the debit is written, so the balance must be exact at the write. Agreed: never, for a user.
  4. Who asks about history, and how far back? This sets whether the past can be thrown away. Agreed: auditors and a regulator, any account as of any moment, for 7 years.
  5. Does money enter or leave through a bank here? A yes brings in an outside party. Agreed: out of scope. Top-ups and withdrawals are the payment system's path, in Chapter 24, and every transfer here is between two accounts you hold.

In this chapter a debit lowers an account's balance and a credit raises it. That is Chapter 24's rule seen from your own books, because a balance here is what you owe the person who holds it.

The second question comes before any protocol has a name. Put it in the product's terms: "If the sender's money has gone and the receiver's hasn't arrived, is anyone allowed to see that? I can't choose how this commits until I know."

Requirements, and Three Things Left Out

The wallet does four things. It holds a balance per account. It transfers between two accounts. It shows a balance and its history. And it gives any balance as of a past moment.

The non-functional list is where this problem lives. No money created or destroyed, with proof on demand. Both sides or neither. Under a second at peak. A committed transfer survives the loss of any machine. Availability of 99.99 percent, about four minutes a month, which leaves no time to wake a person, so failover is automatic. And when in doubt, refuse: a refused transfer costs a retry, and a wrong one costs money.

Fraud scoring, identity checks and the bank path stay out, and you name all three. Each would take a round to itself, and naming them lets the interviewer pull one back in while that is cheap.

The Holiday Against an Assumed Limit

Start from an ordinary day. A hundred million transfers over about 100,000 seconds is 1,000 a second. An ordinary peak of twice that is 2,000.

The holiday is twenty times the average, which makes 20,000 a second. For scale, that is two and a half times what Visa averages and about a quarter of its stated capacity. So it is a serious number, and you say that it is an assumption the interviewer can move.

The estimate that decides needs a number nobody can look up. This course's numbers sheet has no throughput for one relational database, on purpose, as Chapter 1's Estimates That Decide Something explains. So state one and hand it over: "I'll assume a load test puts this schema at 5,000 transfers a second on one primary. Move that if you have a better number. An ordinary day fits, and the holiday is four times over, so the accounts get split."

The split has its own sum. Once the two sides live apart, a transfer writes four rows: a debit and a row of the transfer on the sender's side, a credit and a row of the transfer on the receiver's. At 20,000 a second that is 80,000 writes. One key-value partition takes 1,000 writes a second, and half of that, 500, is what you plan on. That gives 160 partitions, about the number of machines the history needs anyway.

History sets the number of machines. An entry is one side's record of a transfer, so an ordinary day writes 200 million of them. At about 200 bytes an entry, a day is 40 gigabytes, which comes to about 15 terabytes a year, and just over 100 terabytes in 7 years. Three copies make about 307 terabytes. Assume 2 terabytes a node, and that takes about 150 nodes, holding the 160 partitions between them.

Balance reads decide nothing. Each is one key on the account's own shard, so you say that and move on.

The holiday against the assumed limit
Transfers100 million a day, 20 times at peak
1,000 a second, 20,000 at peak. Four writes each, at 500 a partition: 160 partitions. Four assumed primaries, at an assumed 5,000 a second each, a number the interviewer can move.
Storage7 years, 400 bytes a transfer, 3 copies
306.6 TB with copies, about 307. At an assumed 2 TB a node, 154 storage nodes, about 150.

API and Entities

The API is three calls. A POST to transfers carries a transfer ID the client makes, the two accounts and an amount in whole cents, and it returns committed or refused. A GET on an account's balance takes an optional as-of time, and a GET on its entries lists its history. There are three entities: an account with a balance, a transfer, and an entry.

The calls
POST /transfers
  {"transfer_id": "t-7f3a", "from": "acct-1", "to": "acct-2", "amount_cents": 2500}
  200 {"state": "committed"}
  200 {"state": "refused", "reason": "balance"}

GET  /accounts/acct-1/balance
  200 {"balance_cents": 81200}
GET  /accounts/acct-1/balance?as_of=2026-11-03T14:00:00Z
  200 {"balance_cents": 64300, "as_of_sequence": 18422}
GET  /accounts/acct-1/entries?after_sequence=18000

None of the client's values are trusted. The signed-in user must hold the sending account, the amount must be above zero, and the two accounts must differ and both exist and be open, because a negative amount would pull money out of someone else's. The ID is unique per sender, so nobody can burn another person's IDs, and a repeat that names different accounts or a different amount is refused. Balances, history and as-of answers go to the account's holder and to the auditor's role, and nobody else.

Interview Pitfalls
  • Quoting a number for one database as if it were known. The interviewer asks where it came from, and you have nothing. State an assumption and let them move it.
  • Skipping "may anyone see it half done?", then defending a saga to a product that said no pending.
  • Pulling the bank path in, which trades this problem's hard part for a different one and spends the round on it.
What Interviewers Listen For
  • The holiday set against an assumed limit, as a multiple, in spoken steps.
  • The question about half-done visibility, asked before any protocol is named.
  • The bank ruled out by name, and handed to the problem that owns it.

Knowledge Check

You have time for one question before you name how two of your own shards commit. Which answer picks it?

  • Whether anyone may ever see a transfer half done
  • How many accounts the wallet holds in five years
  • Whether money can enter the wallet through a bank
  • How far back an auditor can ask about one account

The holiday is 20,000 transfers a second, and each one writes four rows. One partition takes 1,000 writes a second. How many partitions?

  • 20, which is one for each 1,000 transfers a second
  • 40, which is 20,000 transfers at 500 a partition
  • 80, which is 80,000 writes at 1,000 a partition
  • 160, which is 80,000 writes at 500 a partition

A user's balance may never go below zero. What does that floor force on the design?

  • A cached balance read first, to spare the store a read
  • A balance that is exact at the moment of the debit
  • A job that recomputes all the balances every night
  • A credit that is written before the debit goes in

You rule the bank path out and hand it to the payment system. What does that remove from this problem?

  • The coordinator, since every account is your own
  • The audit duty, since no outside money comes in
  • The outside party, and any outcome left unknown
  • The holiday peak, since banks made the day busy

You got correct