Design a cash machine (ATM)
hard 85 minCard, PIN, notes.
Watch lesson5:10
Where it shows up
The same pattern appears across everyday software.
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.
SQLite: atomic commit
A rollback journal is written and flushed before the database file changes. After a power failure the next reader finds the hot journal and rolls back. Our journal with the same habit.
PostgreSQL: PREPARE TRANSACTION
A prepared transaction can be committed later, also after a crash and from another session. The manual warns against leaving it prepared for long, the trouble of holds that never end.
Azure: compensating transaction pattern
For steps that cannot share one transaction, undo the finished ones by opposite steps. It asks for idempotent commands, and says that sometimes only a person can repair.
Amazon Builders' Library: retries and idempotent APIs
Malcolm Featonby explains requests with a client's identifier, including late arrivals and the same identifier with another intent.
moov-io/iso8583
A Go library for the card message standard ISO 8583, whose readme lists purchases, withdrawals, reversals and balance inquiries. The bank side of a machine, as messages.
EMV chip cards
EMVCo manages the specifications for chips that talk to a terminal. A card that answers is an object with behaviour, unlike the text in our toy.
PCI PIN Security
A standard for handling PINs in machines and during processing. The reason why our PIN is an argument and never a field.