InterviewDryRun
Low-level design interview · Asked at junior and mid level

Design a Vending Machine (Low-Level Design)

How the interviewer asks it

“Design a vending machine with products that have stock and a price, coins and notes, selection, payment, change and refunds. Model it as states such as idle, has money, dispensing and out of service, and show which actions are valid in each.”

Typed drills are free and unlimited: the AI scores your answer against the outline below.

What the interviewer is looking for

  • The state pattern, or an explicit transition table, instead of flags scattered across methods.
  • Clear behaviour for invalid actions in each state.
  • A change-making approach that can fail gracefully when there is not enough change.
  • Inventory and cash kept as separate components.

How to structure your answer

  1. 01

    Clarify

    Accepted denominations, one product per transaction, what happens if change cannot be made.

  2. 02

    States

    Idle, HasMoney, Dispensing, OutOfService, each implementing insertMoney, select, cancel, dispense.

  3. 03

    Components

    Inventory (slot → product and count), CashBox (denomination → count), and the machine holding the current state.

  4. 04

    Change

    Greedy over denominations works for standard coin sets; check it can be paid before dispensing, otherwise refund.

  5. 05

    Edge cases

    Sold out after money is inserted, cancel mid-transaction, power loss during dispensing.

Best answers from candidates

No candidate answers yet. Type yours, and if it scores 6 or more you can show it here without your name.

Answers are shared by candidates, without names, after a privacy check. Add yours

Common mistakes

  • Booleans like isPaid and isDispensing that can contradict each other.
  • Dispensing before checking change can be returned.
  • No refund path on cancel.

Follow-up questions to expect

  • Add card payments where authorisation happens asynchronously.
  • Report sales and stock to a central server.

Now answer it out loud

Max will ask you this exact question, listen to your answer, push on the weak spots with follow-ups like the ones above, and score you when you finish.

Practice with Max

Free: a 5-minute voice round and unlimited typed drills, with scored feedback. No card, and your camera is never recorded.

More low-level design interview questions

Preparing for this round? Read how to prepare for a low-level design (LLD) interview.