Design a cash machine (ATM) 00:00:00 Make a prediction You will separate a bank hold from physical cash delivery and describe a safe outcome when the dispenser's response is unknown. The bank holds forty dollars. The dispenser times out just as the notes may be leaving the slot. Is it safe to refund immediately and try dispensing again? No. The machine may already have handed out cash. Record the operation as uncertain and reconcile the journal, dispenser evidence and bank hold before choosing capture, reversal or another action. 00:00:35 The notebook in the machine A clerk keeps a notebook beside drawers of notes. The bank clerk speaks by phone. Between writing paying and recording paid the lights can go out, so the notebook must say exactly which step was attempted. The bank owns balances; the machine owns notes and local evidence. Distinguish confirmed failure, confirmed physical delivery and a genuinely unknown outcome. A cash machine lets a person take notes from an account. It reads a card, asks a bank whether the PIN and the amount are fine, and moves notes to a slot. It is asked because everyone has used one, and because it separates drawings from designs. A menu with states takes ten minutes. The question of what happens when the light goes out takes the rest of the hour. 00:01:22 Connect the ledger to physical cash A customer requests forty dollars. The bank authorizes a hold and the machine verifies that a valid set of notes is available. The dispenser is a physical boundary. A clear failure before cash leaves can release the hold; a confirmed dispense can complete the withdrawal under the agreed protocol. A timeout can leave the outcome unknown. Journal the operation identifier and reconcile instead of both refunding and dispensing again. The bank balance and cash bin are separate sources of evidence. The bank reserves the withdrawal, then the dispenser loses contact after attempting cash delivery. Debiting again may double-charge; automatically reversing can give away cash. Persist the operation identity and uncertain outcome so reconciliation can make one final decision using bank and device evidence. 00:02:24 Enough total cash can still be unusable A machine holds only twenty-dollar notes and a customer requests thirty. Its total cash may exceed thirty, yet no exact bundle exists. Check denominations before promising success and test both sufficient-value and exact-combination conditions. Even a machine containing hundreds of dollars in twenties cannot dispense exactly thirty. Check the denomination combination before promising cash. If ten-dollar notes later become available, the same withdrawal can succeed without any change in the account balance rule. Enough total cash does not ensure an exact denomination bundle. Test a request the available notes cannot represent before making an irrevocable promise. Start with a single-machine state model; add recovery records at the actual external boundaries instead of treating every internal step as a network transaction. Stripe: authorize, then capture. A hold is placed on a payment method and captured later. An authorization that is not captured in time runs out, and the funds are released. TigerBeetle: two-phase transfers. A pending transfer reserves an amount. It is then posted, voided, or runs out by its timeout, and it can be resolved only once. Hold, commit and release as database operations. 00:03:45 Try an interview follow-up Two people withdraw from one account at two machines. Where is the race? The race is at the shared bank balance. Each machine can protect its own dispenser and still approve against the same funds as another machine. I would have the bank conditionally reserve the amount and record the withdrawal reference together. If there are insufficient available funds, the second reservation must fail. Cash reached the customer but the receipt printer failed. The user presses retry. Which action may repeat? Reprint the receipt using the original withdrawal identifier. Do not dispense again or create a new debit. Keeping the financial and cash outcomes separately from the optional receipt makes a retry safe and explainable. 00:04:38 What to take with you Draw the border first: balances, tries and limits belong to the bank, notes and a journal to the machine. Both sides of the machine are interfaces, and both can fail: the bank by silence, the dispenser by not knowing. A withdrawal plans, then holds, pays and commits, with a journal line before each step. After a stop, the last line decides: release, commit, or ask the sensors. If they do not know, the hold stays and a person counts.