Design an elevator system
Design the classes and scheduling logic for a building's lifts.
Why interviewers ask it
It tests state machines, scheduling and concurrency, and there's no single right answer, so your reasoning is what gets marked.
Functional requirements
- Hall calls (up and down buttons on each floor) and car calls (floor buttons inside the lift).
- Several lifts; each hall call is assigned to one lift.
- Doors open and close; show the current floor and direction.
- Emergency stop and maintenance mode.
Non-functional requirements
- Short waiting times; people on far floors must not wait for ever.
- Safety: never move with the doors open.
From version 1 to the final design
- Version 1: one lift with a list of requested floors, visited in order of arrival.
- Version 2: one lift using LOOK scheduling: sweep up, then down.
- Version 3: several lifts and a controller that gives each hall call to the lowest-cost lift.
- Version 4: safety states (doors, overload, maintenance) and strategies for busy times.
The design, step by step
- Each lift serves its stops with the LOOK algorithm: keep going in one direction, serving stops on the way, then turn around — like a lift operator sweeping up and down.
- A controller assigns each hall call to the best lift: idle and near, or already moving towards that floor in the same direction.
- Each lift has a state machine that enforces safety: doors must be closed before moving.
Deep dives
- Dispatch cost = distance + stops on the way + a penalty for the wrong direction.
- Peak times: in the morning rush, send idle lifts back to the ground floor.
- Concurrency: requests arrive from many buttons at once, so use a thread-safe queue into the controller.
- Overload sensor: the doors stay open.
Common mistakes
- Serving requests first-come, first-served: the lift zig-zags between floors instead of picking people up on its way.
- No state machine, so 'moving with the doors open' is possible.
- Over-complicating the dispatch algorithm before the basics work.
Not true: Dispatch: serving calls strictly in the order they were made keeps the lift's travel shortest.
In fact: The lift then zig-zags between floors. Picking up the calls that lie on its way, in its current direction, moves more people with less travel.
In the interview
A controller receives hall calls and gives each one to the lift with the lowest cost: near, idle, or already heading that way. Each lift serves its stops with the LOOK algorithm — continue in one direction, then reverse. A state machine per lift guarantees the doors are closed before it moves.
Part of Unit 7: Low-level design questions in the free System Design course.