System design interview: design an elevator system
"Design an elevator system" asks you to control one or more cars in a building so that people wait as little as possible and nobody waits forever. It is a modeling and scheduling question: separate hall calls (someone on a floor pressing up or down) from car calls (a floor button inside the car), give each car a simple rule for the order it serves stops, and add a dispatcher that decides which car answers each hall call.
By Evin JohnPublished 8 min read
1. Clarify the requirements
This prompt belongs to the same family as the parking lot and the vending machine: mostly classes and logic, with an optional distributed layer. Agree on the building first.
- Functional: up and down buttons on each floor; floor buttons inside each car; cars move, stop, open and close doors; displays show each car's floor and direction; maintenance mode takes a car out of service; fire mode sends cars to a set floor.
- Non-functional: minimize average and worst-case wait; never starve a request; never move with doors open; behave safely on power loss; one failed car must not stop the others.
- Ask about: number of floors and cars, peak patterns (morning up-peak in offices), service elevators, VIP or restricted floors, and whether riders enter their destination in the lobby.
2. Estimate the scale
| Quantity | Assumption | Result |
|---|---|---|
| Building | 20 floors, 4 cars | the scope of one controller |
| Peak demand | a few hundred people arriving in 15 minutes | a new hall call every few seconds |
| Decisions | re-plan whenever a call arrives or a car reaches a floor | a handful of decisions a second, computed in milliseconds |
| Portfolio | 5,000 buildings sending status every 10 seconds | about 500 status messages a second to a monitoring backend |
Computation is trivial. What matters is choosing a fair scheduling rule, keeping safety logic separate, and handling component failures.
3. Define the interface
Dispatcher.hall_call(floor, direction) -> assigned car id
Dispatcher.car_call(car_id, floor) (button pressed inside a car)
Dispatcher.tick() -> each car moves one floor, opens doors, or idles
Car hardware -> controller: arrived(floor), doors_closed, overload, door_obstructed, fault(code)
Controller -> car hardware: move(direction), stop_at(floor), open_doors, close_doors4. Sketch the classes
| Class | Responsibility | Key fields or methods |
|---|---|---|
Car | Its position, direction and set of stops; decides its next move | floor, direction, stops, step(), cost(floor, dir) |
Dispatcher | Assigns each hall call to one car | hall_call, car_call, tick |
HallPanel / CarPanel | Button input and lights | emit requests; light until served |
Door | Open, close, obstruction handling | state, dwell timer |
SafetyController | Interlocks below the scheduler | blocks motion if doors open, overload, emergency |
Display | Shows floor and direction | subscribes to car updates |
Keep SafetyController out of the scheduling classes. A scheduling bug should, at worst, make people wait; it should never be able to move a car with open doors.
5. The core logic: LOOK per car, cost-based dispatch
Each car follows the LOOK rule (an elevator algorithm also used for disk scheduling): keep going in the current direction while there are stops ahead, serve them in order, and reverse only when nothing is left in that direction. A request behind the car waits at most one sweep, so nothing starves. The dispatcher estimates, for every car, how many floors it would travel before reaching the caller, and picks the cheapest.
UP, DOWN, IDLE = 1, -1, 0
class Car:
def __init__(self, cid, floor=0):
self.id, self.floor, self.direction = cid, floor, IDLE
self.stops = set()
def cost(self, floor, want):
"""Rough floors-to-travel estimate used by the dispatcher."""
if self.direction == IDLE:
return abs(self.floor - floor)
ahead = (floor - self.floor) * self.direction >= 0
if ahead and want in (self.direction, IDLE):
return abs(floor - self.floor)
# must finish this sweep first: go to the farthest stop, then come back
far = max(self.stops, key=lambda s: (s - self.floor) * self.direction, default=self.floor)
return abs(far - self.floor) + abs(far - floor)
def step(self):
"""Advance one tick with the LOOK rule. Returns the floor served, if any."""
if self.floor in self.stops:
self.stops.discard(self.floor)
if not self.stops:
self.direction = IDLE
return self.floor # doors open this tick
if not self.stops:
self.direction = IDLE
return None
if self.direction == IDLE:
nearest = min(self.stops, key=lambda s: abs(s - self.floor))
self.direction = UP if nearest > self.floor else DOWN
if not any((s - self.floor) * self.direction > 0 for s in self.stops):
self.direction = -self.direction # nothing ahead: reverse
self.floor += self.direction
return None
class Dispatcher:
def __init__(self, cars):
self.cars = cars
def hall_call(self, floor, want):
car = min(self.cars, key=lambda c: (c.cost(floor, want), c.id))
car.stops.add(floor)
return car.id
def car_call(self, car_id, floor): # button pressed inside a car
self.cars[car_id].stops.add(floor)
def tick(self):
return [(c.id, c.step()) for c in self.cars]- Simplifications to say out loud: stops do not remember the requested direction, so a car going up also stops for someone who wants to go down; a fuller version keeps separate up and down stop sets per floor and serves each in its own sweep.
- Cost function. Distance is a proxy. Real controllers also weigh the number of stops already planned, how full the car is, and the energy used.
- Re-assignment. Committing a hall call to a car forever can be suboptimal when traffic changes. Some systems re-evaluate unserved assignments as cars move, but changing the car shown to a waiting person is confusing, so many lock the assignment once announced.
6. The architecture
- Field devices
- Hall and car buttons
- Door and load sensors
- Position encoders
- Displays
- Safety
- Interlocks and emergency stop (hardware and firmware)
- Control
- Car controller per car
- Group dispatcher
- Building gateway
- Status and fault events
- Remote mode changes
- Backend
- Monitoring and alerts
- Trip history
- Maintenance scheduling
The layering is the point. Safety is enforced locally, in dedicated hardware and firmware, independent of any software above it. Dispatching runs in the building. The cloud backend is optional for operations: a building must run normally when its internet connection is down.
7. Better dispatching for busy buildings
- Up-peak. In the morning most trips start in the lobby. Send idle cars back to the lobby and let full cars run express to the upper floors they need.
- Zoning. Assign groups of floors to particular cars at peak times so each car makes fewer stops.
- Destination dispatch. Riders enter their destination floor in the lobby and the system tells them which car to take, grouping people going to nearby floors. It needs a keypad or app instead of plain up and down buttons.
- Measure. Track average wait, the long tail (worst one percent of waits) and trip time. Optimizing only the average can leave some floors waiting badly.
8. What breaks, and what you do about it
| Failure | Effect | Mitigation |
|---|---|---|
| A car faults | Its assigned calls are stuck | Mark it out of service and re-assign its hall calls to other cars at once |
| Door blocked repeatedly | Car stuck at a floor | Obstruction sensor reopens; after several attempts, slow forced close with a warning tone where codes allow, and alert |
| Overload | Unsafe to move | Load sensor holds the car with doors open and a message until weight drops |
| Power cut | Cars stop between floors | Emergency power or rescue mode moves cars to the nearest floor and opens doors |
| Dispatcher software crashes | No new assignments | Cars continue serving their own stops; a fallback mode answers hall calls with the nearest car; watchdog restarts |
9. Trade-offs to discuss
- Simple LOOK or optimized dispatch. LOOK per car is predictable and starvation-free; optimizing across cars cuts average wait but is harder to reason about.
- Lock or re-assign hall calls. Re-assigning improves efficiency; locking keeps the lobby display trustworthy.
- Average or worst-case wait. Minimizing the average can starve quiet floors; adding an age penalty to old requests protects them.
- Destination dispatch or classic buttons. Grouping riders moves more people at peak but needs new panels and some rider education.
10. How to talk through it in the interview
Fictional example
- Interviewer
- Someone on floor 2 wants to go up while a car keeps serving calls between floors 10 and 18. Could they wait forever?
- Candidate
- Not with LOOK. The car keeps its direction only while there are stops ahead. Once it has served the last stop in that direction it reverses and sweeps the other way, so floor 2 is reached within one full sweep. With several cars the dispatcher also gives that call to whichever car has the lowest cost, which is often an idle one.
- Interviewer
- What if all cars stay busy at the top?
- Candidate
- I would add an age term to the cost so a call that has waited long becomes cheap to serve first, and cap how many new stops a car accepts in its current direction while an old call is pending.
- Separate hall calls and car calls in your first sentence about the model.
- Write the single-car rule before adding a dispatcher, the same narrow-then-widen pacing described in the interview framework.
- Mention safety as its own layer; it shows you would not let scheduling code move doors.
Practicing this design with Natively
Elevator questions are easy to over-engineer, so practice saying the simple rule first and adding complexity only when pushed. On a practice call, Natively transcribes what you and your partner say, running on your Mac or Windows computer, and when you request it, suggests points for the current question, for example starvation or a faulted car. Ask it to draw the control layers to compare with yours, or share a screenshot of your code for a hint while practicing. The transcript afterwards shows how long you took to reach a working single-car rule.
Questions people ask
How do you design an elevator system in an interview?
Separate hall calls (a floor and a direction) from car calls (a destination inside a car). Give each car the LOOK rule for ordering its stops, add a dispatcher that assigns each hall call to the car with the lowest estimated cost, and keep safety interlocks in their own layer below scheduling.
What is the LOOK algorithm for elevators?
The car keeps moving in its current direction while it has stops ahead and serves them in order, then reverses when nothing is left in that direction. Because every request is reached within one sweep, no request waits forever, which is the main property interviewers ask about.
How does a dispatcher choose which elevator answers a call?
It estimates a cost for each car, such as the floors it must travel before reaching the caller, including the detour when the car is moving away or has stops to finish. It assigns the call to the cheapest car, and better versions also weigh load, stops already planned and how long the call has waited.
What is destination dispatch?
Riders enter their destination floor in the lobby instead of pressing up or down, and the system tells each rider which car to take. Grouping people going to nearby floors means fewer stops per trip, which helps most at busy times such as the morning arrival peak.
Where to go next
Practice with the same assistant you would use on a call: it listens, transcribes and suggests answers from your own resume and the job description.
Facts on this page were last checked on . Product details come from the Natively app itself; if something here is out of date, tell us at hello@heynatively.com.
