Design Amazon Locker System

Difficulty: MEDIUMCategory: LLDFrequency: 1Asked On 2025-04-06

Problem Statement

Design the Low-Level Design (LLD) of an Amazon Locker System, which allows customers to pick up or return packages from self-service lockers instead of home delivery.

The system should manage locker allocation, package storage, pickup, return, and locker status tracking efficiently, while ensuring security and timely delivery.


Your goal is to focus on object modeling, class interactions, and state management, not large-scale distributed architecture.


🎯 Goal


Design a system that can:


β€’Manage multiple locker locations.
β€’Allocate lockers based on package size and availability.
β€’Handle package delivery (by courier) and pickup (by customer).
β€’Manage OTP or code-based authentication for access.
β€’Track locker usage, capacity, and time limits.


βœ… Functional Requirements


1. Locker Setup


β€’Each Locker Location has:
β€’A unique ID and address.
β€’Multiple lockers (small, medium, large).
β€’Each locker can hold one package at a time.
β€’Lockers can be:

Available

Occupied

Out of Service


2. Package Delivery (Courier Flow)


β€’When a courier delivers a package:
1.System finds an available locker suitable for the package size.
2.Allocates locker and stores package.
3.Generates a pickup code/OTP for the customer.
4.Sends a notification (email/SMS) to the customer with locker details and pickup code.


3. Customer Pickup Flow


β€’Customer visits locker location.
β€’Enters pickup code or scans QR code.
β€’System verifies code β†’ unlocks locker.
β€’Customer retrieves package.
β€’Locker marked Available again.


4. Package Return Flow (Optional)


β€’Customer chooses to return a package via locker.
β€’System finds an empty locker, generates a return code, and provides instructions.
β€’Customer deposits the return package β†’ locker locked again β†’ courier picks up later.


5. Locker Timeout


β€’Packages must be collected within a specified time window (e.g., 48 hours).
β€’If time expires:
β€’Locker marked as Expired.
β€’Package returned to warehouse or flagged for escalation.


βš™οΈ Non-Functional Requirements


β€’Thread-safe allocation (no two couriers get the same locker).
β€’Secure authentication (unique OTPs, limited access).
β€’Fault-tolerant (handle locker malfunction gracefully).
β€’Extensible β€” future features like temperature control or IoT sensors.


🧱 Key Classes to Design


ClassResponsibility


AmazonLockerSystem


Main orchestrator; manages locker locations, packages, and operations.


LockerLocation


Represents a location with multiple lockers.


Locker


Represents an individual locker unit (id, size, status).


Package


Represents a parcel to be stored or delivered.


LockerManager


Handles locker allocation, release, and status updates.


NotificationService


Sends pickup codes and alerts to customers.


AccessCode


Represents OTP or code for locker access.


User


Represents customer or courier.


TimerService


Handles locker timeout or expiry logic.


🧩 Example Class Relationships

1 2AmazonLockerSystem 3 β”œβ”€β”€ List<LockerLocation> 4 β”œβ”€β”€ allocateLocker(Package) 5 β”œβ”€β”€ releaseLocker(AccessCode) 6 β”œβ”€β”€ sendNotification(User, AccessCode) 7 8LockerLocation 9 β”œβ”€β”€ String id 10 β”œβ”€β”€ Address address 11 β”œβ”€β”€ List<Locker> 12 13Locker 14 β”œβ”€β”€ String id 15 β”œβ”€β”€ LockerSize size 16 β”œβ”€β”€ LockerStatus status 17 β”œβ”€β”€ Package package 18 β”œβ”€β”€ AccessCode code 19 20Package 21 β”œβ”€β”€ String trackingId 22 β”œβ”€β”€ LockerSize size 23 β”œβ”€β”€ User recipient 24 β”œβ”€β”€ Date deliveryTime


πŸ”„ Example Flow


🧺 Package Delivery


1.Courier arrives with package P123 (medium size) for customer Sahil.
2.System searches for an available medium locker at nearby location.
3.Allocates locker L-07.
4.Generates pickup code: 493201.
5.Sends notification:
1 2Your package is ready for pickup! 3Locker: L-07, Location: HSR Layout, Code: 493201


πŸšͺ Customer Pickup


1.Customer enters code 493201 at kiosk.
2.System validates and unlocks L-07.
3.Customer retrieves package.
4.Locker status β†’ AVAILABLE.


🧾 Example Input / Output


Input:

1 2Package: ID=P123, Size=MEDIUM, Customer=Sahil 3LockerLocation: HSR Layout

Output:

1 2Locker Allocated: L-07 3Pickup Code: 493201 4Pickup Expiry: 48 hours


πŸ” Concurrency & Safety


β€’Use synchronized locker allocation to prevent duplicate assignments.
β€’Access code is one-time use and expires after 48 hours.
β€’Locker should not open unless a valid code is entered.


🧠 Possible Extensions


β€’Smart lockers with sensors to detect if package is placed/picked.
β€’Integration with IoT devices for door control.
β€’Support for temperature-controlled lockers (for groceries).
β€’Support for returns and multi-package deliveries.


βœ… Summary:


Design a Locker Management System (LLD) that:


β€’Allocates lockers based on package size and availability,
β€’Generates and validates secure access codes,
β€’Handles package pickup, return, and timeout,
β€’Ensures secure and concurrent locker usage.


Focus on object modeling, locker allocation logic, and secure access handling.

Solution

Comments