Jump to a problem, path or page
Jump to a problem, path or page
01 · Frame the problem
Design the objects and contracts for a multi-floor parking lot. Motorcycles, cars and trucks need compatible spaces. Concurrent arrivals must never receive the same spot.
Separate spot-selection preferences from exclusive ownership and ticket/payment lifecycle. The hardest cases are competing arrivals and ambiguous payment outcomes, where a locally convenient action can violate another operation's ownership.
02 · Find the design pressure
Begin with spots and active tickets behind one service. A check-then-assign implementation races, while unconditional exit release is unsafe. Move claims into an atomic repository operation and make payment/receipt identity part of ticket state.
03 · Define success
04 · Identify the correctness boundary
Selection ranks candidates; only the repository's conditional claim owns a spot. Keep claim and ticket creation atomic, and freeze the exit quote before calling payment outside the transaction. Payment identity belongs to the ticket workflow, while release verifies that the spot is still owned by that ticket.
05 · Make it concrete
Two cars choose the last car-sized spot. One claim succeeds; the other retries and returns LotFull. The winner exits, but payment times out. Its spot remains occupied until reconciliation confirms the same payment. Repeating exit then returns the stored receipt and cannot release another driver's spot.