Design a parcel locker 00:00:00 Make a prediction You will assign an appropriately sized locker once and make old pickup credentials invalid after reassignment. A customer collected parcel A from locker three yesterday. Parcel B is behind the same door today. Should yesterday's valid code still open it? No. The code belongs to the old parcel assignment, not to door three forever. Validate the current assignment and consume or invalidate its credential after successful collection. 00:00:32 The bread doors at the old mill A mill has bread doors in different sizes. A note identifies the door and today's loaf. After a customer takes the bread, that note cannot also claim the next loaf put behind the same door. Door, parcel and assignment are different identities. Select a fitting free door atomically, then tie pickup and expiry to that particular assignment. A parcel locker in a low-level design round is the software behind a wall of doors. It chooses a door for a parcel, gives the customer a secret that opens exactly this door, and knows when the door can be used again. Everybody has seen one, so there is nothing to explain, and the conversation is soon about what happens between two steps. 00:01:19 Track a parcel through one door A courier needs the smallest free locker that fits a parcel. Select and claim the locker together, then associate it with one parcel and a pickup credential. A customer's valid credential identifies that assignment. If collection succeeds, close the assignment and return the locker to the free pool. An old credential must fail after the locker is reassigned. Test reuse of the same physical door with a second parcel to expose stale mappings. Assign C four to a parcel, issue its pickup code and complete the delivery. Reassign C four to a later parcel. Enter the earlier code again: an implementation keyed only by door number may open the wrong delivery. Bind the code to its assignment and expiry. 00:02:06 The actuator reports uncertainty A door command times out. The service cannot infer that the door stayed closed or that the parcel was collected. Record the uncertain state and reconcile with the locker or attendant before treating the door as free. Storage state and physical state are separate facts. Send an unlock command and lose the acknowledgment. The door may have opened. A timeout alone cannot prove that it stayed closed. Store the operation identity, query the available evidence and reconcile before promising the compartment is free for a different parcel. A timeout from the door actuator proves neither successful pickup nor certain failure. Releasing the locker immediately could let a courier overwrite a still-occupied assignment. Model an explicit inspection or uncertain state where the physical device cannot confirm its outcome. Redis: how keys expire. A key with a time to live is removed passively, when somebody asks for it and it is too late, and actively, by testing random keys in the background. Comparing at pick up and sweeping for lists is the same pair. Amazon SQS: visibility timeout. A received message is hidden for a time, 30 seconds by default. It must be deleted, or it becomes visible again. A lease with a confirmed end, where software may take the thing back by itself. 00:03:32 Try an interview follow-up How do you make sure that two couriers do not get the same door? Finding and taking is one step: pop from the queue of free doors under the locker's lock. The unlock comes after the lock, because a relay can be slow. There is no public question whether a door is free. Two small compartments are free and a courier arrives with one large parcel. Can a system reporting two free doors confirm delivery? No. The contract requires a single eligible compartment large enough for this parcel. Preserve the free-door count when refusing the assignment. If larger compartments can serve smaller parcels, specify that fallback separately. 00:04:17 What to take with you A door is free, loading, holding or emptying. The code is made when the loaded door has been shut, belongs to the stay and works once, until its end. The door is free when it has been shut again. Decide under one short lock, move metal and send messages outside it. The end of the code is a comparison, the end of the occupation needs a person. For real hardware write the intent first and compare with the sensors after a restart.