Skip to content
Low Level Design Mastery Logo
LowLevelDesign Mastery

Design Elevator Management System - Single Lift

Design a single elevator system with efficient request queue management and direction optimization.

What is the Elevator System - Single Lift Problem?

Section titled “What is the Elevator System - Single Lift Problem?”

Design an elevator management system for a single elevator car in a building. The system should efficiently handle internal requests (from inside the elevator) and external requests (from floor buttons), manage direction-based request prioritization, handle state transitions (IDLE, MOVING_UP, MOVING_DOWN, STOPPED), and coordinate door operations.

In this problem, you’ll design a system that focuses on request queue management, direction optimization, and state transitions without the complexity of coordinating multiple elevators.


Design a single elevator system that efficiently processes requests through intelligent queue management and direction-based prioritization.

Functional Requirements:

  • Single Elevator Car: Manage one elevator car that can access all floors in the building.
  • Request Types: Handle both external requests (users pressing up/down buttons on floors) and internal requests (users selecting destination floors from inside the elevator).
  • Request Queue: Maintain a queue of pending requests and process them efficiently based on current direction and floor position.
  • Direction Optimization: When moving UP, prioritize requests above current floor going UP, and internal requests to floors above. When moving DOWN, prioritize requests below current floor going DOWN, and internal requests to floors below.
  • State Management: Handle states (IDLE, MOVING_UP, MOVING_DOWN, STOPPED) with proper transitions.
  • Door Operations: When elevator arrives at a requested floor, stop, open doors, wait briefly, close doors, and continue processing requests.
  • Concurrent Requests: Handle multiple simultaneous requests from different users without conflicts.
  • Idle Behavior: When IDLE, process the closest request (any direction).

Non-Functional Requirements:

  • Modular Design: Each class should have well-defined roles following the Single Responsibility Principle.
  • Extensibility: Easy to add new request prioritization strategies or elevator features without refactoring.
  • Thread Safety: Request handling and elevator state updates must be thread-safe for concurrent requests.
  • State Pattern: Use State Pattern to manage elevator states and transitions cleanly.
  • Testability: Core elevator logic should be easy to test, understand, and maintain.

The system coordinates between users, the elevator system, and display components, focusing on single elevator management.

Diagram
classDiagram
    class ElevatorSystem {
        -Elevator elevator
        -int totalFloors
        +requestElevator(int, Direction) void
        +selectFloor(int) void
    }
    
    class Elevator {
        -int currentFloor
        -Direction direction
        -ElevatorState state
        -List~Request~ requestQueue
        +addRequest(Request) void
        +move() void
        +getNextRequest() Request
    }
    
    class ElevatorState {
        <<interface>>
        +handleRequest(Elevator, Request) void
        +move(Elevator) void
    }
    
    class Request {
        -int floor
        -Direction direction
        -RequestType type
    }

    ElevatorSystem --> Elevator
    Elevator --> ElevatorState
    Elevator --> Request
    ElevatorState <|.. IdleState
    ElevatorState <|.. MovingUpState
    ElevatorState <|.. MovingDownState
    ElevatorState <|.. StoppedState

Diagram

When the elevator is moving UP, it should prioritize requests above the current floor going UP, and when moving DOWN, prioritize requests below going DOWN.

Solution: Implement direction-based filtering in getNextRequest(). Filter requests based on current direction and floor position. When moving UP, select closest request above current floor going UP or internal requests above. When moving DOWN, select closest request below current floor going DOWN or internal requests below.

Elevator must transition between states (IDLE → MOVING_UP/DOWN → STOPPED → MOVING_UP/DOWN → IDLE) correctly based on requests and movement.

Solution: Use the State Pattern. Define ElevatorState interface with implementations (IdleState, MovingUpState, MovingDownState, StoppedState). Each state handles requests and movement differently, and manages transitions to appropriate next states.

The system needs to efficiently prioritize requests while handling concurrent additions and removals.

Solution: Use thread-safe collections (synchronized lists or concurrent queues) for the request queue. Implement direction-based prioritization logic that filters and selects requests based on current state and direction. Consider using priority queues for more efficient selection.

Multiple users can request elevators simultaneously from different floors, requiring thread-safe operations.

Solution: Implement thread-safe operations using synchronized methods, thread-safe collections, and fine-grained locking. Ensure request queue operations (addRequest(), getNextRequest()) and state updates are atomic.


By solving this problem, you’ll master:

  • State Management - Controlling object lifecycles with the State Pattern.
  • Queue Management - Efficient request prioritization and processing.
  • Direction Optimization - Intelligent request selection based on movement direction.
  • Observer Pattern - Decoupled notifications to displays.
  • Concurrency - Thread-safe operations for concurrent requests.

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

After mastering Elevator System - Single Lift, try these similar problems: