Locker Management System
What is the Locker Management System Problem?
Section titled “What is the Locker Management System Problem?”Design a Locker Management System for warehouse packages that assigns packages to available lockers based on size, manages locker states (Available, Occupied, Out of Order), generates secure access codes for package pickup, notifies recipients when packages are stored, handles package expiration and cleanup, supports searching by tracking number/recipient/locker number, and operates across multiple warehouse locations.
In this problem, you’ll design a system that efficiently manages package storage and retrieval using lockers of various sizes, while incorporating key design patterns to ensure scalability, maintainability, and flexibility.
Problem Overview
Section titled “Problem Overview”Design a comprehensive system that manages warehouse lockers for package storage, ensuring efficient space utilization, secure access, and automated expiration handling.
Core Requirements
Section titled “Core Requirements”Functional Requirements:
- Locker Assignment: Assign incoming packages to available lockers based on package size and locker availability.
- Locker Sizes: Manage lockers of different sizes (Small, Medium, Large, XL) and match packages to appropriate locker sizes.
- Access Control: Generate unique, secure access codes (6-digit alphanumeric) when packages are assigned to lockers.
- Locker States: Track locker states (Available, Occupied, Out of Order) and manage state transitions properly.
- Notification: Notify recipients when their packages are stored, providing locker number and access code.
- Expiration: Handle package expiration (e.g., 7 days) and automatically release expired packages and their lockers.
- Search: Support searching for packages by tracking number, recipient information (name/email), or locker number.
- Multi-location: Support multiple warehouse locations, with each location having its own set of lockers.
- Retrieval: Allow recipients to retrieve packages using the access code.
- Maintenance: Allow staff to mark lockers as Out of Order and restore them to Available state.
Non-Functional Requirements:
- Object-Oriented Design: Clear separation of concerns with well-defined roles for each class.
- Modularity: Easy to add new locker sizes, assignment strategies, or notification methods without modifying existing code.
- Thread Safety: Package assignment, retrieval, and state transitions must be safe from race conditions.
- Performance: Efficient locker assignment and search operations even with large numbers of lockers and packages.
- Maintainability: Core locker management logic should be robust, testable, and maintainable over time.
- State Management: Locker state management should be robust and prevent invalid state transitions.
What’s Expected?
Section titled “What’s Expected?”1. System Architecture
Section titled “1. System Architecture”The system manages multiple warehouses, each with its own set of lockers. Packages are assigned to lockers based on size matching strategies.
2. Key Classes to Design
Section titled “2. Key Classes to Design”classDiagram
class LockerManagementSystem {
-Map~String,Warehouse~ warehouses
-Map~String,Locker~ lockers
-Map~String,Package~ packages
+storePackage(Package, String) String
+retrievePackage(String, String) Package
+searchByTrackingNumber(String) Package
}
class Locker {
-LockerState state
-Package pkg
-String accessCode
+assignPackage(Package) boolean
+releasePackage(String) Package
}
class LockerState {
<<interface>>
+assignPackage(Locker, Package) boolean
+releasePackage(Locker, String) Package
}
class LockerAssignmentStrategy {
<<interface>>
+assignLocker(Package, List~Locker~) Locker
}
LockerManagementSystem --> Locker
Locker --> LockerState
LockerManagementSystem --> LockerAssignmentStrategy
LockerState <|.. AvailableState
LockerState <|.. OccupiedState
LockerAssignmentStrategy <|.. SmallestFitStrategy
System Flow
Section titled “System Flow”Package Storage Flow (State Transitions)
Section titled “Package Storage Flow (State Transitions)”Package Retrieval Flow
Section titled “Package Retrieval Flow”Key Design Challenges
Section titled “Key Design Challenges”1. Managing Locker States
Section titled “1. Managing Locker States”Lockers can be in three states: Available, Occupied, or Out of Order. Each state has different allowed operations.
Solution: Use the State Pattern. Create state classes (AvailableState, OccupiedState, OutOfOrderState) that encapsulate state-specific behavior. The Locker class delegates all operations to its current state object, eliminating complex if-else chains.
2. Matching Packages to Lockers
Section titled “2. Matching Packages to Lockers”A small package can fit into small, medium, large, or XL lockers, but we want to optimize space by using the smallest available locker.
Solution: Use the Strategy Pattern. Create assignment strategy classes (SmallestFitStrategy, ExactMatchStrategy) that encapsulate different matching algorithms. The system can swap strategies at runtime without modifying existing code.
3. Access Control & Security
Section titled “3. Access Control & Security”Recipients need secure access codes to retrieve packages. Codes must be unique, random, and validated.
Solution: Generate 6-character alphanumeric codes when packages are assigned. Store codes in lockers and validate them during retrieval. Clear codes after successful retrieval.
4. Package Expiration
Section titled “4. Package Expiration”Packages should expire after 7 days and be automatically released to free up lockers.
Solution: Track storedAt and expiresAt timestamps in packages. Use an ExpirationHandler that periodically checks for expired packages and releases them automatically.
What You’ll Learn
Section titled “What You’ll Learn”By solving this problem, you’ll master:
- ✅ State Pattern - Managing complex state transitions with clear behavior encapsulation.
- ✅ Strategy Pattern - Implementing flexible, swappable algorithms for package-to-locker matching.
- ✅ Factory Pattern - Creating objects without exposing creation logic.
- ✅ Access Control - Secure code generation and validation mechanisms.
- ✅ Multi-location Architecture - Managing distributed resources across locations.
- ✅ Thread Safety - Ensuring concurrent access safety with fine-grained locking.
View Complete Solution & Practice
Section titled “View Complete Solution & Practice”Ready to see the full implementation? Open the interactive playground to access:
- 🎯 Step-by-step guidance through the 8-step LLD approach
- 📊 Interactive UML builder to visualize your design
- 💻 Complete Code Solutions in Python, Java, C++, TypeScript, JavaScript, C#
- 🤖 AI-powered review of your design and code
Related Problems
Section titled “Related Problems”After mastering the Locker Management System, try these similar problems:
- Parking Lot System - Similar state management and space allocation challenges.
- Vending Machine - State pattern and inventory management.
- Car Rental System - State pattern, strategy pattern, and resource management.