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 Published 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

One building, then a portfolio (assumed figures)
QuantityAssumptionResult
Building20 floors, 4 carsthe scope of one controller
Peak demanda few hundred people arriving in 15 minutesa new hall call every few seconds
Decisionsre-plan whenever a call arrives or a car reaches a floora handful of decisions a second, computed in milliseconds
Portfolio5,000 buildings sending status every 10 secondsabout 500 status messages a second to a monitoring backend
One building, then a portfolio (assumed figures). Scroll sideways on a small screen.

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_doors
Events into the controller and the commands it issues

4. Sketch the classes

Classes and responsibilities
ClassResponsibilityKey fields or methods
CarIts position, direction and set of stops; decides its next movefloor, direction, stops, step(), cost(floor, dir)
DispatcherAssigns each hall call to one carhall_call, car_call, tick
HallPanel / CarPanelButton input and lightsemit requests; light until served
DoorOpen, close, obstruction handlingstate, dwell timer
SafetyControllerInterlocks below the schedulerblocks motion if doors open, overload, emergency
DisplayShows floor and directionsubscribes to car updates
Classes and responsibilities. Scroll sideways on a small screen.

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]
One tick moves each car one floor or opens its doors. Simulated with random calls on 20 floors and 1 to 4 cars: every request was served, the worst wait was 61 ticks.
  • 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

  1. Field devices
    • Hall and car buttons
    • Door and load sensors
    • Position encoders
    • Displays
  2. Safety
    • Interlocks and emergency stop (hardware and firmware)
  3. Control
    • Car controller per car
    • Group dispatcher
  4. Building gateway
    • Status and fault events
    • Remote mode changes
  5. Backend
    • Monitoring and alerts
    • Trip history
    • Maintenance scheduling
Control layers in a building and a monitoring backend. Hall buttons, car buttons, door sensors, load sensors and position encoders connect to a controller in the machine room. Inside it, a safety layer enforces interlocks and can stop any car, a car controller per car runs motion and doors, and a group dispatcher assigns hall calls across cars. A gateway sends status and fault events from many buildings to a central monitoring backend, which alerts technicians, stores trip history and lets operators change modes such as maintenance.

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 modes worth naming
FailureEffectMitigation
A car faultsIts assigned calls are stuckMark it out of service and re-assign its hall calls to other cars at once
Door blocked repeatedlyCar stuck at a floorObstruction sensor reopens; after several attempts, slow forced close with a warning tone where codes allow, and alert
OverloadUnsafe to moveLoad sensor holds the car with doors open and a message until weight drops
Power cutCars stop between floorsEmergency power or rescue mode moves cars to the nearest floor and opens doors
Dispatcher software crashesNo new assignmentsCars continue serving their own stops; a fallback mode answers hall calls with the nearest car; watchdog restarts
Failure modes worth naming. Scroll sideways on a small screen.

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

Answering "how do you prevent starvation?"
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.

Keep reading

Put it on your own machine.

A live-conversation assistant that runs locally. Your conversations stay on your machine.

macOS 12+ · Windows 10/11

© 2026 Natively AI Private Limited

Source-available under the Natively Personal Use Source License v1.0 · IP geolocation by DB-IP