Design a vending machine 00:00:00 Make a prediction You will trace inventory, customer credit and change together, and decide what the machine must check before an irreversible dispense. A drink costs seventy-five cents. A shopper inserts a dollar, but the machine has no combination of coins worth twenty-five cents. Should it release the last drink? Only if the agreed policy allows a sale without exact change and the customer accepts it. Under an exact-change promise, reject or refund before dispensing and leave the stock unchanged. 00:00:37 A morning at the deckchair hatch A miniature chair appears in the vending window. The buyer's coin sits in a temporary tray until the machine knows it can supply both the chair and the change. A jam after that point is a different failure from a refused sale. Model the allowed transitions and identify what money is still returnable at each step. Distinguish deciding a sale from observing a physical dispense. A vending machine is a shop without a person. It takes money, checks, gives a product, gives change, and must be right when nobody is there to say sorry. The domain is known to everyone, so the interview reaches design within a minute. 00:01:18 Vend the final snack once A snack costs seventy-five cents and exactly one remains. The customer inserts a dollar and selects it. Before committing, verify stock and the ability to return twenty-five cents under the machine's change policy. Keep the transaction coherent if either check fails. On success, issue one snack, update stock, and return change. Pressing the selection again must not vend the same unit or reuse the old credit. Start two selections with only one item behind the motor. The machine must reserve the specific vend before promising both customers a result. A jam after the reservation changes the recovery path; marking the sale complete before motor confirmation loses evidence about whether cash should be returned. 00:02:08 Cannot make change A machine has sufficient total cash but lacks the denominations needed to return ten cents. It must refuse or follow a clearly disclosed exact-change policy before taking an irreversible action. Test both the displayed outcome and the customer's refunded credit. The cash balance is sufficient for the price, but the customer needs ten cents back and no permitted coin combination exists. Refuse or ask for exact payment before releasing the snack. Total cash value is a different condition from the ability to make exact change. A sufficient total cash balance does not imply the correct denominations exist. Test a rich machine with no way to make the small required change. Keep change selection as a replaceable policy if denominations or planned inventory constraints vary. MDB/ICP. The multi-drop bus used inside vending machines, published by the National Automatic Merchandising Association. Coin changers and card readers hang on one bus, behind one protocol, as our Motor and Tender hang behind interfaces. Stripe manual capture. A payment can be authorised now and captured later. The authorisation expires, and the amount is released if nobody captures it. That is hold, take and release. 00:03:31 Try an interview follow-up How do you test that no money is lost? I would track where every coin can be after each action. Initial cash plus inserted cash must equal cash in the box, cash in escrow and money returned. Then I would jam the simulated motor, repeat a button press and replay a refund. Those failures test whether an apparently balanced success path can still lose money. A customer pays the exact price but the motor reports a jam. Trace the cash, the item's availability and the customer's result. Do not record a successful vend before the outcome is known. Introduce an explicit recovery state if the machine cannot determine whether the item dropped. 00:04:18 What to take with you Coins are a list in escrow until something has fallen. Change is planned from the box and the escrow with a search, before the product. The order is check, plan, claim, drop, settle, and each refusal moves nothing. A short lock covers the decisions, a busy flag covers the motor. A known jam puts everything back, an unknown result stops the machine. Cards fit the same shape: hold, take, release.