Design locker allocation service
Company: Amazon
Role: Software Engineer
Category: System Design
Difficulty: hard
Interview Round: Technical Screen
Amazon Locker OS provides a set of LockerIDs. Locker and package sizes are Small, Medium, and Large. Each locker may hold at most one package. Design the component that manages the set of lockers and returns the best-fitting LockerID when a courier arrives with a package. Clearly define "best fit" (e.g., prefer exact size; allow upsizing rules and their priority). Specify core operations (register lockers, mark available/occupied, assign, release on pickup, query status), data structures, and time/space complexity. Address concurrency (simultaneous couriers), idempotency and retries, race conditions, and fairness/starvation. Describe persistence and failure recovery. Provide APIs, schema, and pseudocode for assign(packageSize) and release(lockerId). Consider extensions such as reservations, per-location sharding, priorities/SLA tiers, and scaling.
Quick Answer: This question evaluates a candidate's understanding of stateful system design, resource allocation strategies, concurrency control, API and data modeling, and fault tolerance in the context of real-time locker assignment.