Amazon Lock (OOD) Overview
The "Amazon Lock" or "Amazon Locker" problem is a common Object-Oriented Design (OOD) interview question at Amazon, focusing on designing a locker system for package delivery and pickup. It tests skills in backend system design, OOD principles, web integration, and sometimes machine learning for optimization like locker selection. The core scenario involves drivers depositing packages into automated lockers and customers retrieving them via access codes.[1][3]
Customers order items on Amazon and opt for locker delivery at nearby locations (e.g., stores or malls). Delivery personnel deposit packages into available compartments of appropriate sizes (small, medium, large). The system generates a unique access token (e.g., 6-digit code) sent to the customer via email/SMS, valid for a limited period (typically 3-7 days). Customers enter the code at the locker to open the compartment and retrieve the package.
Key requirements:
Out of scope: Delivery logistics, payment, UI rendering, multiple locker networks.[3][7][1]
From typical implementations (e.g., Java/C++ class designs):
Deposit Package:
Input: locker.depositPackage(PackageSize.MEDIUM) Logic: Finds free medium compartment (e.g., "B"), opens it automatically, generates token "ABC123" (expires in 7 days), marks occupied. Output: "ABC123" (token for customer notification)
State change: Compartment B occupied, token mapped to B.[1]
Pickup Package:
Input: locker.pickupPackage("ABC123") Logic: Validates token (exists, not expired), opens compartment B, marks free, removes token mapping. Output: void (door opens physically; errors thrown if invalid/expired: "Access token expired" or "Invalid code").
Failed case (expired): Throws error, compartment stays locked/occupied.[1]
Staff Clear Expired:
Input: locker.clearAllExpired() Logic: Opens all compartments with expired tokens for manual package removal/return to sender. Output: void (multiple doors open).
Core classes: Locker, Compartment, AccessToken, PackageSize.
Locker manages compartment array and token map.