Implement a Self-Service Kiosk Vending Machine as a State Machine
Last updated: November 29, 2026
Quick Overview
Design and implement the core logic of a vending kiosk in an Amazon office break room: it accepts coins, lets the user select an item, dispenses it if paid in full and in stock, returns change, and supports cancel. Model it as an explicit state machine.
Amazon
November 29, 20260
0
0 solved
Design and implement the core logic of a vending kiosk in an Amazon office break room: it accepts coins, lets the user select an item, dispenses it if paid in full and in stock, returns change, and supports cancel. Model it as an explicit state machine.
A classic low-level design problem in the style of Amazon onsite rounds. The interviewer checks whether you model states explicitly (rather than a tangle of booleans), reject invalid actions per state, and handle money with integer cents and a correct change algorithm.
What the Interviewer Expects
- Identify states: Idle, HasMoney, Dispensing (or fold dispensing into a transition)
- Use integer cents for money
- Reject actions that are invalid in the current state
- Return change and handle insufficient change
- Keep inventory updates consistent on failure
Key Topics to Cover
How to Approach This
- Apply SOLID principles. Single Responsibility makes code testable, Open/Closed makes it extensible.
- Choose data structures based on access patterns, not familiarity.
- Prefer immutable data and message passing over shared mutable state for concurrency.
- Design APIs with RESTful conventions, versioning, meaningful errors, and pagination from day one.
Possible Follow-up Questions
- How would you use the State pattern with one class per state?
- How would you handle a coin jam or power loss mid-dispense?
- How would you add card payments?
Sharpen Your Skills on Codemia
Practice similar problems with our interactive workspace, get AI feedback, and track your progress.
Practice System Design ProblemsSample Answer
Requirements
Coins accepted: 5, 10, 25, 100 cents. Items have a slot code, price and quantity. Actions: insert(coin), select(code), cancel(). Selecting with insufficient balance or out-of-stock items keeps the bal...
High-Level Design
Stateenum with IDLE and HAS_MONEY. Dispensing is an atomic transition, not a waiting state, because the hardware call is synchronous here.Kioskholdsitems,balance,coinsreserve (den...