Low-level design9 min read

Design an Elevator System: A Low-Level Design Walkthrough

The elevator is one of the most common low-level design prompts because it packs everything into one small domain: clear entities, a state machine, a scheduling algorithm you can improve step by step, and concurrency once buttons are pressed from every floor at once. This walkthrough is for software engineers. It follows the flow from Low-Level Design Interviews: Modeling a System in Code and notes, at each step, what a strong candidate does that a weaker one skips. The code is Java.

Step 1: Clarify the requirements

The prompt is usually one sentence: "Design an elevator system for a building." Spend the first five minutes turning it into a contract. A strong candidate asks and then writes down the answers:

  • How many floors and elevators? Assume one building, N floors, M elevators.

  • What requests exist? Hall calls (a person on a floor presses up or down) and car calls (a person inside presses a destination floor).

  • What does the system decide? Which elevator answers each hall call, and in what order each elevator visits its stops.

  • Special modes? Maintenance mode for now; mention fire service and express elevators as extensions.

  • Out of scope: motor control, weight sensors, door hardware. You model the controller, not the machinery.

State one non-functional goal too: keep average wait time low and never starve a request. That goal is what will justify your scheduling choice later.

Tip

Write the requirements as a short list on the board. When the interviewer adds a twist later, you can point to what changes and what does not.

Step 2: Find the entities and their responsibilities

Name each class with one sentence of responsibility. If you cannot, the class is doing too much.

  • ElevatorSystem: accepts requests and hands hall calls to an elevator. It owns the list of elevators and the dispatch strategy.

  • Elevator: knows its floor, direction and pending stops, and moves one floor per tick.

  • ElevatorState: what the elevator does right now (idle, moving, doors open, under maintenance). Each state decides the next one.

  • DispatchStrategy: picks the elevator for a hall call. Swappable.

  • HallCall: a floor and a direction. Car calls are just a floor added to one elevator.

Weaker candidates put everything in one Elevator class with a large if on a status string. Splitting state and dispatch out is what lets you handle the extensions in Step 6 without rewriting anything.

Step 3: Model the elevator as a state machine

An elevator has a small set of states with clear transitions:

IDLE --(stop requested)--> MOVING --(arrived at stop)--> DOORS_OPEN
  ^                                                         |
  +----------------(doors closed, no stops)-----------------+
DOORS_OPEN --(doors closed, more stops)--> MOVING
any state --(maintenance on)--> MAINTENANCE --(maintenance off)--> IDLE

The state pattern turns each box into a class, so adding a state never touches the others:

interface ElevatorState {
    void step(Elevator elevator);
    boolean acceptsHallCalls();
}

final class IdleState implements ElevatorState {
    public void step(Elevator e) {
        if (e.nextTarget().isPresent()) {
            e.setState(new MovingState());
        }
    }
    public boolean acceptsHallCalls() { return true; }
}

final class MovingState implements ElevatorState {
    public void step(Elevator e) {
        Optional<Integer> target = e.nextTarget();
        if (target.isEmpty()) {
            e.setState(new IdleState());
            return;
        }
        e.moveOneFloorToward(target.get());
        if (e.currentFloor() == target.get()) {
            e.clearStop(target.get());
            e.setState(new DoorsOpenState(3)); // doors stay open for 3 ticks
        }
    }
    public boolean acceptsHallCalls() { return true; }
}

final class DoorsOpenState implements ElevatorState {
    private int ticksLeft;
    DoorsOpenState(int ticks) { this.ticksLeft = ticks; }

    public void step(Elevator e) {
        ticksLeft--;
        if (ticksLeft == 0) {
            e.setState(e.nextTarget().isPresent() ? new MovingState() : new IdleState());
        }
    }
    public boolean acceptsHallCalls() { return true; }
}

final class MaintenanceState implements ElevatorState {
    public void step(Elevator e) { /* parked: does nothing */ }
    public boolean acceptsHallCalls() { return false; }
}

Step 4: Decide the order of stops inside one elevator

There are two scheduling problems, and naming them separately is a strong move: which elevator answers a hall call (Step 5), and in which order one elevator visits its stops (here).

The naive order is first come, first served. It sends the car up and down the building chasing requests in arrival order and wastes most of its travel. The better order is the one real elevators use, often called LOOK: keep going in the current direction while there are stops ahead, then reverse. It is the same idea as the elevator algorithm for disk scheduling, and it guarantees that every stop is served within one sweep up and one sweep down, so nothing starves.

A sorted set makes this short:

enum Direction { UP, DOWN }

final class Elevator {
    private final int id;
    private int currentFloor = 0;
    private Direction direction = Direction.UP;
    private final TreeSet<Integer> stops = new TreeSet<>();
    private ElevatorState state = new IdleState();

    Elevator(int id) { this.id = id; }

    void addStop(int floor) { stops.add(floor); }
    void clearStop(int floor) { stops.remove(floor); }
    void step() { state.step(this); }
    void setState(ElevatorState next) { state = next; }

    Optional<Integer> nextTarget() {
        Integer ahead = stopAhead();
        if (ahead == null && !stops.isEmpty()) { // reverse only toward a real stop
            direction = (direction == Direction.UP) ? Direction.DOWN : Direction.UP;
            ahead = stopAhead();
        }
        return Optional.ofNullable(ahead);
    }

    private Integer stopAhead() {
        // ceiling/floor include the current floor, so a stop here is served now.
        return direction == Direction.UP ? stops.ceiling(currentFloor) : stops.floor(currentFloor);
    }

    void moveOneFloorToward(int target) {
        if (target > currentFloor) currentFloor++;
        else if (target < currentFloor) currentFloor--;
    }

    int currentFloor() { return currentFloor; }
    Direction direction() { return direction; }
    boolean isIdle() { return state instanceof IdleState && stops.isEmpty(); }
    boolean acceptsHallCalls() { return state.acceptsHallCalls(); }
    int farthestStopAhead() {
        if (stops.isEmpty()) return currentFloor;
        return direction == Direction.UP ? Math.max(stops.last(), currentFloor)
                                         : Math.min(stops.first(), currentFloor);
    }
}

One refinement to mention: a person waiting on floor 5 to go down should not be picked up by a car passing floor 5 on its way up. Keeping hall stops tagged with their direction fixes this; the single set above is the version you write first.

Step 5: Dispatch hall calls with a strategy

Put the choice behind an interface so you can start simple and improve:

record HallCall(int floor, Direction direction) {}

interface DispatchStrategy {
    Optional<Elevator> choose(HallCall call, List<Elevator> elevators);
}

A simple strategy: the nearest idle elevator. Easy to explain, and fine in a quiet building. It fails at rush hour: when every car is moving, nobody is idle, and a car about to pass the caller's floor in the right direction is ignored.

A better strategy: lowest estimated travel cost. Estimate how many floors each car must travel before reaching the caller, and pick the cheapest:

final class TravelCostStrategy implements DispatchStrategy {
    public Optional<Elevator> choose(HallCall call, List<Elevator> elevators) {
        return elevators.stream()
            .filter(Elevator::acceptsHallCalls)
            .min(Comparator.comparingInt(e -> cost(e, call)));
    }

    private int cost(Elevator e, HallCall call) {
        int here = e.currentFloor();
        int distance = Math.abs(here - call.floor());
        if (e.isIdle()) {
            return distance;
        }
        boolean onTheWay = e.direction() == call.direction()
            && (e.direction() == Direction.UP ? call.floor() >= here : call.floor() <= here);
        if (onTheWay) {
            return distance;
        }
        // Must finish the current sweep, turn around, then come back.
        int turn = e.farthestStopAhead();
        return Math.abs(here - turn) + Math.abs(turn - call.floor());
    }
}

Explain the trade-off: the cost is an estimate that ignores door time and future requests, but it captures the main effect, which is direction. You can add a small penalty per pending stop to spread load.

The controller ties it together:

final class ElevatorSystem {
    private final List<Elevator> elevators;
    private final DispatchStrategy strategy;

    ElevatorSystem(List<Elevator> elevators, DispatchStrategy strategy) {
        this.elevators = elevators;
        this.strategy = strategy;
    }

    void hallCall(HallCall call) {
        strategy.choose(call, elevators)
            .orElseThrow(() -> new IllegalStateException("No elevator in service"))
            .addStop(call.floor());
    }

    void carCall(int elevatorIndex, int floor) {
        elevators.get(elevatorIndex).addStop(floor);
    }

    void tick() {
        elevators.forEach(Elevator::step);
    }
}

Step 6: Handle the extensions without a rewrite

This is where the earlier structure pays off. For each twist, say which class changes and which do not.

  • Maintenance mode. Already a state. Turning it on also has to hand the car's pending hall calls to other elevators, which belongs in ElevatorSystem. Car calls from passengers already inside are finished first in a real building; say which you choose.

  • Express elevators that serve only the lobby and floors 20 and up. Add a canServe(floor) check on Elevator; the strategy filters on it. No state changes.

  • Fire service mode. A new state that ignores all calls and drives to the lobby, plus a system-level switch that puts every car into it. Existing states stay untouched.

  • Peak-hour dispatch. A new DispatchStrategy (for example, park idle cars at the lobby before 9 a.m.), swapped in by time of day.

Weak and strong answers to the same twist

The interviewer says: "Two of the four cars are now express: lobby and floors 20 and up only."

The weak answer opens Elevator.tick() and adds if (isExpress && floor > 1 && floor < 20) skip, then adds the same check to the dispatcher, then to the button panel. Three classes change for one rule, the state classes now know about building policy, and the next twist (a freight car that serves the loading dock) will add a fourth branch to each. Against the bar in the low-level design quick start, this loses on boundaries and extensibility, and the candidate usually cannot say in one sentence where the rule lives.

The strong answer names the change before touching code: "Which floors a car serves is a property of the car, and choosing a car is the strategy's job. So Elevator gets a canServe(floor) backed by a set of floors, the strategy skips cars that cannot serve the call, and the states do not change." It writes those few lines, then checks the edge the twist creates: a passenger inside an express car presses 12, so the panel must reject it, and that check reuses canServe. One rule, one home, and a test the candidate can describe: dispatch a call from floor 12 and assert it never reaches an express car.

Step 7: Concurrency

Buttons are pressed on every floor while the controller moves the cars, so stops is shared between threads. Two reasonable answers:

  • Guard each elevator. Make addStop, clearStop and nextTarget synchronized on the elevator. Simple, but easy to get wrong as methods multiply.

  • A single controller thread. Button presses become events on a bounded BlockingQueue; one thread takes events and runs ticks, so the model itself is single-threaded. This is easier to reason about and is how many real controllers work.

Concurrency in Low-Level Design Interviews covers both tools in depth.

Follow-ups to expect

  • "How do you guarantee no request waits forever?" Every hall call is assigned to an in-service car the moment it arrives, and LOOK serves every stop on that car within one sweep each way.

  • "How would you test the scheduler?" Drive tick() from a test with scripted calls and assert the order of floors visited; the tick-based design makes this deterministic.

  • "What if an elevator breaks mid-trip?" Move it to maintenance and re-dispatch its hall calls.

What changes with seniority

A junior candidate should produce working classes and a state machine. A mid-level candidate should separate dispatch from per-car scheduling and justify LOOK over first come, first served. A senior candidate should also handle extensions by naming the class that changes, address concurrency unprompted, and discuss what the cost function ignores.

Mistakes that cost points

  • One giant Elevator class with status strings and nested conditionals.

  • Mixing the two scheduling problems, so the dispatcher also orders stops.

  • First come, first served with no discussion of travel waste or starvation.

  • Ignoring direction on hall calls.

  • Coding before the requirements are written down, then discovering express elevators halfway through.

Practice it

Redraw this design from memory in 30 minutes, out loud, then add one extension the lesson did not cover (a capacity limit per car) and say which classes change. SmartIntervu has no dedicated low-level design format yet; the closest practice is the LRU cache problem, which tests the same class design and invariant thinking in code. It is scored as a coding interview, so the habits above land directly: clarifying requirements counts toward problem solving, one-sentence responsibilities toward code quality, and a scripted test of the invariant toward testing and edge cases.

Practise this in a mock interview

Try what this lesson covers out loud: the AI interviewer asks one of these questions, follows up, and scores your answer.

Read next

  • Low-Level Design Interviews: Modeling a System in Code

    Turn a small real-world system into classes and interfaces with a seven-step flow, apply SOLID and four core patterns where they earn their place, and extend the design without rewriting it.

    8 min read

  • Concurrency in Low-Level Design Interviews

    Spot the check-then-act races concurrency adds to a design, fix them with the right tool (concurrent collection, lock, atomic, read-write lock or bounded queue), avoid deadlock with lock ordering, and answer the multi-server follow-up.

    8 min read