Ch.42: Amazon Locker System Design: The Door Opened Too Late

Outline

Transcript

0:00 In our fictional Amazon Locker design, parcel A has been collected. Compartment seven now holds B. Then Maya's old pickup command arrives. Its signature is valid. The door opens for somebody else's parcel. Oh, man. A genuine permission reached the wrong physical moment. Checking who signed it wasn't enough. We'll follow Maya's pickup to the motor, including one power cut where a careful system still has to say, “I don't know whether it opened.” Let's put Maya's command on the whole-system map. It started in the cloud.

0:31 Which component actually gets to open seven? Only the locker controller opens seven. Cloud stores her instruction; a queue carries it. Before motor movement, the controller journals locally, keeping a record across reboot. Physical evidence returns to the cloud. Right. Asking from the cloud doesn't settle what the latch did. We'll return to this exact map once we've followed Maya through those paths. Before the controller, Maya's functional requirements are the actions she needs: choosing a locker, getting notified and collecting A, with recovery if pickup fails.

1:05 Her courier needs deposit permission. If seven instantly opens for B, did pickup work? No. That's a coat check returning two coats to the wrong two people. Non-functional requirements concern quality: speed, reliability and durability around the right action. Fast service with the wrong parcel still fails pickup. Right. A's stay in seven is assignment 41; B's next stay gets 42. That counter lets an old permission fail against new contents. I'd keep Maya waiting, I think, rather than open B. With that pickup requirement, a power cut beside Maya at seven gets awkward.

1:42 Before the motor moves, the controller checks signature, expiry, permitted action and the current parcel and assignment. It holds a local lock from checking the assignment through writing the attempt; other allocation requests have to wait. What's written before the pulse? A local journal entry marked prepared. That's a record surviving reboot. Seven is also marked “Maya's pickup has started.” Then the controller requests the motor pulse and loses power before recording its outcome. Wait. On restart it knows the request was prepared, but not whether the latch moved.

2:14 Why not pulse again and let the sensors settle it? No. We can seek physical evidence without requesting another pulse. If it already opened, replay repeats an action we promised not to repeat blindly. If it never opened, saying success leaves Maya outside. Neither answer is justified by that record. That's uncomfortable. A lot of us reach for “safe retry,” but recording one accepted request doesn't record what the motor did. We need an unknown result and a quarantined seven. From the cloud side, Maya's phone says accepted while the locker stays dark.

2:48 I kind of expected the cloud commit to cover that. What did it actually preserve? One database transaction writes two records: Maya's request and an outbox row saying “send this command.” If the server dies before contacting the queue, a relay still finds her instruction. Even a successful queue leaves Maya with a dark locker. We sometimes treat that acknowledgement as completion. Yeah. AWS documents delayed and repeated device messages; sources are in the description. Our relay retries with the same operation identity.

3:21 The cloud can recover delivery, not the observation lost beside seven. Then that relay can deliver Maya's command again at seven. Same operation ID, same requested action. What happens when that exact command comes back? Match it to the journal entry; we're basically reading the recorded answer. A finished pickup keeps its result. A rejected request returns the rejection. Neither path sends a second pulse. And what does Maya get after our blackout? Unknown. While the first process was running, it could report in progress.

3:52 After this reboot without an outcome, it can't pretend the work is still running or start it afresh. Bad news, but at least it doesn't get creative: unknown stays unknown. Could her phone invent a different operation ID? Seven still says “Maya's pickup has started.” A new ID meets that ongoing pickup and is refused. The parcel stays held until physical evidence settles it. Right. The request ID finds the previous answer; the assignment record blocks another attempt. Renaming the request doesn't move Maya past the blackout.

4:25 That unknown answer leaves Maya waiting for physical evidence. An authorized operator can at least inspect seven; the door is closed. Can we call the pickup finished? No. One closed garage can hold one car or none. Door position and contents are separate facts. Maya might, for instance, have opened seven and walked away without taking A. It really doesn't tell us. The authorized operator records a fresh inspection of A in seven, tied to the controller's current assignment 41. That resolves whether the parcel was collected, but not whether the first pulse happened.

5:00 Oh, right. Inspection can justify a separately authorized pickup, with its own record. It doesn't change the first attempt: that motor result stays unknown. Yes. Maya collects A under the new authorization. Door closed plus trusted evidence that A is gone now releases seven. Any conflict keeps it quarantined. Once seven is confirmed empty, a courier deposits B under 42. Maya's original retry can still read its historical result without moving B's door. But what if an unused grant, the pickup permission for 41, reaches us for the first time?

5:34 It must pass the checks for a new opening. The current assignment says B, 42; the grant still identifies A's 41 assignment. Reject it before preparing an attempt or sending power to the motor. Think of a hotel stay numbered 41. Its receipt can still, for instance, retrieve an old record after checkout. But its unused keycard cannot open room seven once stay 42 begins. I like that. Maya can read the old result without opening anything, while her unused grant fails against B. The journal lookup and current-assignment check protect different paths to that door. With that collision resolved, take Maya back to checkout, before A was delivered.

6:14 Choosing expected space is like booking a hotel before receiving a room key. Could an expired reservation free seven for her courier? Imagine the courier arriving while a previous delivery occupies seven. No fitting empty compartment means reroute. An expired row buys exactly zero extra cubic centimeters. Ouch. Operations says, “The hold expired. Free the slot.” So our database is volunteering to carry the box out? I'd use that feature. But no. Our courier still needs an empty fitting door. Amazon's Locker capacity paper explains why reservations matter: standard orders can fill space needed by faster shipments.

6:52 It proposes holding capacity by shipping option. That reserves future space, not an occupied door. So the station has to settle the allocation itself. Maya's courier scans A; the controller finds compartment seven empty and large enough, then durably claims it for A under assignment 41. What stops another courier taking seven? It handles those claims one at a time. The second courier sees seven already held. Our authorized deposit then closes the door. A fresh parcel-sensor reading for that current assignment changes the record to occupied. Now Maya gets “ready.” Oh, right. The notification follows the parcel into seven.

7:29 The cloud reservation couldn't give us that fact. Exactly. The cloud row was, honestly, where I wanted to settle this. But “reserved space” and “A behind seven” need different evidence. With A inside, Maya requests pickup permission. Why not sign one generic “open seven” command? What do we gain by binding it to A's pickup? A generic grant permits opening seven, whatever is inside. Ours authorizes one action for one parcel during one assignment. It names the station, seven, A, 41, and pickup, plus expiry and one operation ID for this attempt.

8:04 A courier's separate grant permits deposit. Same door, different authority. My first thought was a person-bound grant, sort of like a named ticket. Could Maya forward her instructions to a friend? Sure. Amazon's public guide permits sharing pickup instructions. Our design likewise lets whoever holds the grant present it. Think of handing over a train ticket: another passenger can hold it, but the journey and expiry don't change. Right. Different holder, same trip, same deadline. The ticket doesn't buy access to the parcel that replaces A.

8:37 Now return to Maya's first scan with A still inside. Her online grant expires at 12-oh-three, 3 minutes after issue. That short permission is separate from Amazon's U.S. three-calendar-day collection window. Internet drops. Product asks, “A is inside and Maya is right there. Why turn her away just because the connection dropped?” Can she collect? Only for A's current occupied assignment and an unused operation, with trustworthy time. For example, the station display says 2 seconds remain. This station's clock could be 5 seconds slow.

9:10 She might already be 3 seconds late. Refuse access, even with A waiting behind the door. Give me a second. I was trusting the countdown without leaving room for the clock to be wrong. What if its display has a full minute left? Yes. With that uncertainty, 55 seconds remain before expiry. We accept only when the latest possible real time is still before the deadline. Unknown clock error forces refusal; there's no grace. Okay. That gives A's existing pickup some room while new ownership waits. But Product says, “We revoked Maya's grant a moment ago.” The station can't see that offline.

9:48 Right. The difference is how current our permission information is. Online is a live call asking about just-recorded revocations. Offline is the ticket already in our hand, with its deadline and trusted local facts. A ticket can't hear a cancellation made after it was issued. Right. Valid signature, older permission information. Yes. Short expiry limits that exposure. While disconnected, we allow only collection of the parcel already known inside, never deposits or reassignments. With A collected, seven holds B while the cloud still thinks A is there.

10:22 Imagine it receives B's deposit first. Is B replacing A, or did somebody skip an empty check? Ask the station for the missing history. First, Maya collected A. Second, seven was confirmed empty. 3rd, B was deposited under 42. Accept that chain, rather than guessing from the last packet received. Ah, okay. A out, empty, B in. What if the old “A inside” or “seven empty” message arrives next? Keep it historical. Neither can replace B or offer B's compartment to another courier. If we can't recover a missing step or reconcile conflicting evidence, stop new allocation and get physical help.

11:00 Right. That empty message describes A's stay. It isn't permission to take the space back from B. With a separate queue and worker per station, those updates stay ordered. A dead station cannot stall the others. But isolation won't save a controller with stale ownership. What if its disk dies? Imagine operations saying, “Restore yesterday's backup and restart.” It says A, 41, while B physically occupies seven. Could the old A grant match? Ugh. It could match that obsolete record perfectly. A recovery disaster: yesterday's ownership opening today's parcel.

11:35 Replacement stays out of service until trusted current assignment records are recovered, or authorized staff record a new physical inventory. The old database cannot certify today's contents. Wait, that's the gap. I was treating a valid backup as current ownership. Its checksum only proves the bytes survived. Operations asks, “But the backup passed its checksum. Why keep customers waiting?” The checksum can confirm old bytes; it can't confirm B behind seven. We assume one process owns the motor-control connection and journal.

12:07 Replacement cannot create a second owner or guess today's parcel from an old snapshot. If current ownership can't be established, refuse automated pickups at this station. Right. Getting a process running didn't give us current ownership. Yes. Let's trace where that proof comes from. Now return to that same whole-system diagram. The cloud preserves Maya's instruction; delivery retries it. The controller compares today's assignment and records the attempt before reaching the motor. Physical sensing and authorized inspection establish what happened physically.

12:40 Ordered history updates the cloud. Neither a retry, lost power nor an old backup is allowed to turn A's permission into access to B. That's what I like about it. We stopped asking one database row to stand in for a parcel. Right. Let the cloud preserve intent, and let the locker admit what it doesn't know. No component gets to invent the missing proof. And that keeps A's permission away from B. I can trace the next safe decision. Thanks for listening to Learning Podcasts.