Design a parking lot 00:00:00 Make a prediction You will separate physical spaces, live claims and tickets, and trace one admission when two gates compete. One medium space remains. Gate A prints a ticket before taking the space from the free pool. Can gate B print a ticket for the same space? Yes. Printing is not the atomic claim. Remove the suitable space and create the matching ownership record together before reporting a successful admission. 00:00:29 Sandy Point car park, from empty to full and back A seaside lot keeps one numbered disc per free space on a hook. Two clerks may both see disc seven, but only one hand can take it. Put the disc back only when the space is truly free again. The disc is the authoritative availability claim, not the public display. A ticket points at the claimed space and can later support charging and release. A parking lot in a low-level design round is the software at the gates of a car park. It decides which vehicle gets which space, remembers it on a ticket, and at the end turns the time into a price. It is a popular exercise because everybody knows car parks. No time is lost on explaining the domain, so the conversation is about objects from the first minute. 00:01:16 Claim the last medium space A medium car reaches gate A and only space M1 fits. The space pool chooses and removes M1 in one operation. Gate B asks for a medium space at almost the same time. It receives no space unless a larger fallback is both available and allowed. Issue one ticket referencing M1. The display reads availability from the pool instead of maintaining another independent count. On exit, release the space once after the business conditions are satisfied. After both gates show one medium bay available, pause one gate and let the other commit the assignment. The slower gate must receive a refusal, even if its screen still reads one. A printed ticket follows the durable claim so each ticket refers to a real assigned bay. 00:02:05 Handle an uncertain payment A driver pays at exit but the terminal loses the reply. Mark payment unresolved and reconcile using the original payment identifier. Recharging blindly can bill twice; releasing the space while the car still occupies it creates a different inconsistency. Authorize payment and lose the reply before the exit gate records it. An immediate second charge risks charging twice. Keep the payment identifier, check the original result and reopen the exit decision when the uncertainty resolves. Release the bay according to the stated exit policy. If receipt printing fails after a successful claim, repeating the entire entry operation could allocate a second space. Preserve the original ticket identity. If larger spaces may accept smaller cars, make fallback a policy and test the remaining capacity by size class. PostgreSQL can let one worker skip rows already locked by another when claiming work. A connection pool faces a similar ownership issue when it marks one available connection as in use. Both examples separate finding a promising candidate from the indivisible act that makes one caller its owner. 00:03:20 Try an interview follow-up How would you handle high traffic during peak hours? First the sum: ten gates with a car every six seconds are 1.7 claims a second, and a claim takes microseconds, so one lock is idle. What must not happen is slow work inside it. If a profile shows waiting, I split by level: each level has its pool and lock, gates start at different levels, and totals become estimates. A driver needs to move from bay A into bay B after receiving a ticket. If B becomes occupied during the move, what must the ticket say? Claim B and update the assignment under a consistent transition, or retain A if B cannot be claimed. Releasing A before confirming B can leave a valid customer with no space and a ticket pointing to already-reallocated inventory. 00:04:21 What to take with you Two verbs, enter and leave. One owner of free spaces, grouped by size, where finding is taking. Tickets, vehicles and spaces are records. Prices are a rule that is passed in, in whole cents. Check plate, claim and store under one short lock. At the exit take the ticket out, charge without a lock, put it back on failure, and release last. Reject classes that hold nothing, and say so.