Amazon Locker
Package Pickup Locker System
Design a self-service parcel locker site: put each package in the smallest locker it fits, give the customer a single-use code with a deadline, handle returns, and hand overdue packages back to the courier.
Overview
A parcel locker site is a wall of compartments in three or so sizes. A courier arrives with packages, the system opens a locker that fits each one, and the customer gets a code. The customer types the code within the pickup window, the door opens, and the locker is free again. Customers can also reserve a locker to drop off a return. Packages nobody collects in time are taken back by the courier.
This is a design exercise named after a well-known product; it does not describe how Amazon builds its lockers. Interviewers like it because it mixes a fit rule (smallest locker that fits), security (codes that are hard to guess and work once), time (deadlines on every code), and a race (two couriers asking for the last small locker at the same moment).
A strong answer draws the locker states first, keeps a free list per size so allocation is O(1), generates codes with a cryptographic random source, and injects the clock so expiry can be tested exactly.
Scoping the problem
Ask seven questions before you draw a class. Each comes with why it matters and the answer interviewers usually give.
- Which locker sizes exist, and may a small package use a bigger locker? This fixes the fit rule. The usual answer is small, medium and large, and yes, but only when no exact fit is free.
- How long is the pickup window? Every code needs a deadline. The window is a setting; the demo uses 3 days as an example, not Amazon's real window.
- What happens to a package after the window? That needs an overdue state and a courier round. The code stops working, and the courier takes the package back.
- Are returns in scope? They add a reservation before the package exists. The usual answer is yes: reserve, drop off with a code, and the courier collects.
- How are codes delivered, and how long are they? This decides how hard they are to guess. In this design a code is 6 digits, sent by message, and single use.
- One site or a network? A network needs a site chooser. One site here, with the nearest site with space as a follow-up.
- Can a door fail? That adds a maintenance state, which is a follow-up.
Functional requirements
- A site has lockers of three sizes; a package goes into the smallest free locker it fits
- deliver(package, size, now) assigns a locker and returns a 6-digit pickup code with a deadline, or refuses when nothing fits
- pickup(code, now) opens the locker once for a valid, unexpired pickup code and frees it
- request_return(package, size, now) reserves a locker and returns a drop-off code; drop_off(code, now) records the package
- expire(now) voids late codes: overdue deliveries and dropped-off returns are listed for the courier, unused reservations are freed
- collect(locker_id) lets the courier empty only lockers flagged for collection
Non-functional requirements
- No locker is given to two packages: every operation runs under the site lock
- Taking and releasing a locker is O(1): a free list per size
- Codes come from a cryptographic random source, are unique among live codes, single use and time limited
- Time is injected, so expiry is exact in tests
- The pickup and return windows are settings, not constants in the logic
Interview questions
- Six digits is only a million codes. Can someone guess one?
- The customer chose a site that is full. What then?
- A locker door jams. How does the design cope?
- Thousands of sites report to one backend. Where does the lock go then?
- How is the customer told the code, and reminded before the deadline?
Sign up free to read the full topic
More Low-Level Design topics
Start free on Cariara · Coding problems · System design studio