Skip to content
Preptima
hardCodingDesignMidSenior

Design an elevator system for a building with N lifts. When someone presses the call button, which lift answers, and where in your code is that decided?

An elevator system splits into a state machine per lift that decides its own next floor, and a dispatcher that assigns each hall call to one lift through a pluggable strategy such as a nearest-suitable-car cost. Car buttons go straight to their lift, and one control loop owns all state, so no god class and no locks.

6 min readUpdated 2026-10-10

Answer

Short answer

Split the decision in two. In an elevator system, each lift is a state machine that owns its position, direction and stop list, and decides on its own which floor comes next. A separate dispatcher answers the hall call: when someone presses up or down on a landing, it asks a strategy to score every in-service lift and adds the stop to the cheapest one. Buttons pressed inside a car skip the dispatcher entirely, because that passenger has already chosen their lift.

Was this answer helpful?

Likely follow-ups

  • Lift 2 was assigned a call, then a closer lift became free. Do you reassign, and what has to be undone?
  • The building wants two lifts reserved for floors 20 to 40 at peak hours. Which classes change?
  • How would you change the cost function so a lift with eight stops ahead is not picked over an idle one two floors further away?
  • A lift faults with passengers inside and three hall calls assigned to it. Walk me through what happens to each.

Related questions