Skip to content
Preptima

Top 5 State machine Interview Questions

Browse 5 real-world technical and behavioral interview questions about State machine. Review scenarios, edge cases, and architectural best practices.

Design a food-ordering system: customers place orders with restaurants, and the system assigns a delivery partner. Walk me through the classes.

A food ordering design has two lifecycles: the order moves from placed to delivered, while delivery partner assignment runs alongside and can fail and restart. Keep them separate, claim a partner atomically, rank candidates behind a strategy, and write cancellation windows as rules keyed on order state.

mediumdesign

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.

hardcoding

Design a movie ticket booking system with shows, seats and a temporary hold that expires if the user does not pay. Write the classes.

A ticket booking design models a Show that owns its seat states and a Hold with an owner, seat set and expiry. Holds are taken all-or-nothing under a per-show lock, expiry is checked lazily so no timer decides correctness, and starting payment moves the hold to a state the timer can no longer release.

hardcoding

An order moves through a set of states with rules about which transitions are allowed. How would you design that so it does not become a nest of if statements?

Write the legal transitions down as a table first, then give the entity one entry point that consults it and no state setter at all. The design question is where the transition rules live and how side effects stay outside the decision that changed the state.

mediumdesign

A three-line order could be sourced from either of two warehouses. How do you decide where it ships from, and what happens when one line falls through?

Allocation is a cost minimisation over shipping, split-parcel cost and delivery promise, evaluated per line rather than per order; the design that survives is one where every line carries its own state, cancellation is a race against the pick face, and a shortfall is a normal outcome with a defined path.

harddesign