Practice/Amazon/Design Amazon Lockers
Design Amazon Lockers
System DesignMust
Problem Statement
Design a package delivery system that integrates with e-commerce platforms, allowing customers to select locker locations during checkout and securely retrieve their packages using authentication codes. The system bridges online selection, physical locker inventory, courier operations, and on-device authentication to deliver a reliable last-mile experience.
At Amazon, interviewers ask this because it forces you to connect web flows (checkout), logistics (locker capacity and routing), and device constraints (intermittent connectivity, offline auth) under real-world reliability and security requirements. You are expected to reason about inventory reservation, workflow orchestration, contention, idempotency, and near real-time updates.
Key Requirements
Functional
- Locker selection during checkout -- users search and select a nearby locker based on location, hours, and available compartment sizes during the order process
- Delivery and notification -- delivery agents open assigned compartments to drop off packages, confirm delivery, and trigger customer notifications with a secure pickup code
- Secure pickup -- users authenticate at the locker (code, QR, or OTP) to open the correct compartment and retrieve their package
- Expiration and returns -- packages uncollected within the pickup window are flagged for return, with the compartment released for new deliveries
Non-Functional
- Scalability -- support millions of locker compartments across thousands of locations with hundreds of thousands of daily package operations
- Reliability -- ensure no compartment is double-booked; handle locker hardware failures and intermittent connectivity gracefully
- Latency -- return locker availability during checkout within 300ms; authenticate and open compartments within 2 seconds
- Consistency -- strong consistency for compartment reservations to prevent double-booking; eventual consistency for availability search
What Interviewers Focus On
Based on real interview experiences, these are the areas interviewers probe most deeply:
1. Compartment Reservation and Contention
Locker compartments are scarce resources and many customers may target the same location at peak times. Interviewers want to see how you prevent double-booking without sacrificing checkout flow performance.
Hints to consider:
- Use conditional writes (DynamoDB conditional expressions or database optimistic locking) to atomically claim a compartment of the right size tier
- Reserve compartments with TTLs so abandoned checkouts automatically release inventory
- Partition inventory by locker location and compartment size to minimize lock contention scope
- Implement idempotency keys tied to order ID so checkout retries don't create duplicate reservations
2. Multi-Step Delivery Workflow
From checkout reservation to courier delivery to customer pickup to expiration and return, the flow spans multiple services and time windows. Interviewers look for a robust workflow design.
Hints to consider:
- Model the package lifecycle as a state machine: reserved, shipped, delivered, awaiting-pickup, collected, expired, returned
- Use Kafka events to drive state transitions with compensating actions for failures
- Generate secure, short-lived pickup codes bound to (order_id, compartment_id) with expiration timestamps
- Implement retry logic and dead-letter queues for failed state transitions
3. Offline Authentication and Security
Locker hardware may have intermittent connectivity. Users must be able to authenticate and retrieve packages even when the locker cannot reach the central system in real-time.
Hints to consider:
- Pre-load active pickup codes and their compartment mappings to locker hardware during periodic sync
- Support offline code verification using cryptographically signed tokens that the locker can validate locally
- Rate-limit authentication attempts per compartment to prevent brute-force code guessing
- Implement audit logging on the locker device, synced to the central system when connectivity restores
4. Availability Search and Proximity
Showing accurate locker availability during checkout requires efficient geo-spatial queries with real-time inventory data. Interviewers want to see how you keep availability fresh.
Hints to consider:
- Cache locker availability in Redis with per-location keys, updated asynchronously from reservation events
- Use geo-spatial indexes to find nearby lockers within a delivery radius based on the shipping address
- Accept slight staleness in search results (5-10 seconds) and handle conflicts at reservation time with fallback suggestions
- Pre-compute availability for popular delivery zones to reduce query latency during checkout peaks
Suggested Approach
Step 1: Clarify Requirements
Start by confirming scope. Ask about the number of locker locations and compartments, compartment size tiers (small, medium, large), pickup window duration, and whether returns through lockers are in scope. Clarify connectivity assumptions for locker hardware and whether the system needs to handle multiple packages per compartment. Determine if the system integrates with existing order management or operates standalone.