Design a multi-size storage locker system
AmazonSoftware Engineer · OnsiteLast updated
This question tests your ability to design a scalable, distributed reservation system that handles resource allocation (bin packing) under concurrency constraints.
Design a Multi-Size Storage Locker System
Design a backend service for a network of automated storage lockers found in public locations (e.g., apartment complexes or transit hubs). The system must allow users to reserve, deposit, and retrieve packages.
Functional Requirements
- Users can view available locker sizes (Small, Medium, Large) at a specific facility.
- Users can reserve a locker for a limited duration.
- The system must track the state of every locker:
EMPTY,RESERVED,OCCUPIED. - Support package drop-off (transitioning from
RESERVEDtoOCCUPIED) and retrieval (clearing the locker).
Non-Functional Requirements
- Concurrency: Ensure no two users can reserve the same locker simultaneously.
- Scalability: The system should support thousands of facilities globally.
- Availability: Reservations should succeed even if the local kiosk hardware has intermittent connectivity, though the locker state must remain consistent.
Deliverables
- API Design: Define the core endpoints for viewing availability, reserving, and confirming drop-off.
- Data Model: Design the schema for lockers, facilities, and bookings.
- Concurrency Strategy: Explain how you prevent race conditions when multiple users attempt to book the last available locker of a specific size.
- System Architecture: Propose a high-level design that handles the distributed nature of the hardware terminals and the central reservation system.
Hints
Hint 1
Consider using database-level locking or optimistic concurrency control with versioning to manage the 'last available locker' problem.
Hint 2
Think about whether a reservation should be a state transition on a locker object or a separate record in a 'Bookings' table.
Hint 3
Address how you would handle a scenario where a user reserves a locker but never shows up, including the state recovery process.
Follow-up questions
- How would you optimize the system if a facility has thousands of lockers and a high churn rate for reservations?
- How do you handle 'stuck' lockers where a sensor reports an object is present, but the system shows the locker as empty?
- If we introduce a multi-tenant model (e.g., different logistics companies using the same lockers), how would your data model change?
Solution walkthrough is for members
Get the full walkthrough with reference code and complexity analysis, plus Kitty Coach at 300 messages a day. Hints, the code runner and community answers stay free.