Design Amazon Locker
Understanding the Problem
🔐 What is Amazon Locker? Amazon Locker is a network of self-service lockers in places like grocery stores, apartment lobbies and train stations. At checkout, a shopper picks a nearby locker instead of a home address. A driver drops the package into a compartment, the shopper gets a pickup code, and they open the compartment with it at the locker's screen. If nobody collects the package within a few days, it's sent back.
Other parcel lockers (in-store pickup lockers, carrier lockers, apartment package rooms) work the same way, so everything here applies to them too.
This question looks like a small CRUD app at first. The traffic is low. What makes it interesting is that it mixes future capacity (promising a compartment days before the package arrives), a physical device that has to work without a network, and security for a code that opens a box with someone's belongings inside.
Functional Requirements
Core Requirements
- Shoppers should be able to see nearby lockers at checkout and choose one, and only lockers that will have a compartment big enough for their package should be offered.
- Delivery drivers should be able to drop off a package at the locker into a free compartment of the right size.
- Shoppers should get a pickup code once the package is delivered and be able to open their compartment with it. The code keeps working until the package is collected.
- Packages not collected within 3 days should be flagged for return, and their compartments freed.
Below the line (out of scope)
- Returns that customers drop into a locker (it's the same flow in reverse).
- Locker hardware design, installation and site contracts.
- Routing and scheduling of delivery drivers.
Non-Functional Requirements
Ask about scale, but also ask about the physical world: how reliable is the network at a locker site, and what happens when a locker is full? We'll assume 20,000 locker sites with about 60 compartments each in four sizes (S, M, L, XL), so 1.2M compartments, and about 500k locker deliveries a day.
Core Requirements
- A shopper who picks a locker should almost never find, at delivery, that it's full. We'll target under 0.5% of locker deliveries needing a reroute.
- Pickup codes must be unguessable and single use. Nobody should be able to open someone else's compartment.
- Lockers must keep working for drop-off and pickup when their network connection is down, for hours at a time.
- Entering a valid code should open the door within about a second, and the locker list at checkout should load in under 200 ms.
- Every door open must be recorded, so we can answer "who opened compartment M-14 and when?" for any dispute.
Below the line (out of scope)
- Multi-region active-active. Each locker is homed in one region.
- Fraud and abuse beyond the locker itself (stolen accounts, chargebacks).
The back-of-the-envelope:
- Checkout. If ~2M shoppers a day look at locker options, that's ~25 searches per second on average and a few hundred at peak. Selections are fewer: ~500k a day, about 6 per second.
- Locker index. 20k lockers × ~200 bytes = 4 MB. It fits in memory on every server.
- Kiosk traffic. 20k kiosks sending a heartbeat every minute is ~330 messages per second, plus ~1M drop-off and pickup events a day (~12/s).
- Capacity. 1.2M compartments with packages staying up to 3 days. If the average package waits about a day, the network can turn over roughly 1M packages a day, so 500k deliveries uses about half of it on average, with busy lockers much fuller.
Say this out loud in the interview: the scale here is small, and that's not where the difficulty is. The hard parts are promising capacity days in advance, keeping a device and the cloud in agreement when the network drops, and making a six-digit code safe. Candidates who spend their time on sharding miss the point.