SevyDevy

Design a vending machine

PremiumLow-level designEasy

  • State pattern
  • Vending machine
  • Coin change

Quick answer

This low-level design interview question asks you to design a vending machine. Aim for a design that is modelled as clear classes, interfaces and relationships that can handle new requirements without a rewrite. Interviewers want to see how you name responsibilities, keep classes small and reason about change.

The problem

Vending machine low level design: build the object model for a snack machine with 30 slots that takes coins and notes, dispenses the chosen product and returns change. The hard parts are a state machine that never dispenses unpaid or gives change twice, and making change from a limited coin inventory.

A buyer inserts coins or notes, picks a product by its slot code, receives the product and any change. A buyer can cancel before the product is dispensed and get the money back. An operator restocks products and empties the cash box.

What must a vending machine do?

  • Selection: A buyer types a slot code (A1 to F5). If the slot is empty, show "Sold out". If the inserted amount is less than the price, show the remaining amount and wait.
  • Dispense and change: When the amount covers the price, dispense the product and return the difference in the fewest coins possible from the coin inventory.
5 more requirementsUnlock to see all

How well must it do it?

  • No invalid state: The machine must never dispense without full payment, never give change twice, and never accept money while dispensing.
  • Robust: If the dispenser jams, the buyer gets a full refund and the slot is marked faulty.
2 more requirementsUnlock to see all

What scale should you design for?

Use these numbers in your estimates.

The scale numbers unlock with this questionUnlock

Key concepts

  • State pattern
  • Vending machine
  • Coin change
  • Object oriented design
  • Inventory management
  • Refund handling

How you’ll practise

6 short steps · save and come back any time
  1. Requirements
  2. Core objects
  3. Class relationships
  4. Key flows
  5. Extensibility
  6. Wrap-up

Lala, personalized to you, gives a hint when you ask and reviews your design when you are ready.

What do interviewers look for?

In any low-level design round.

  • Lists the use cases before writing classes
  • Gives each class one clear responsibility
  • Uses interfaces where behaviour is likely to change
  • Applies a design pattern only when it solves a real problem
  • Handles edge cases and invalid states explicitly
  • Walks through one use case end to end with the model

Questions people ask about this interview question

Which design type is this question?
It is a low-level design question. You design a vending machine and explain your choices the way you would in an interview.
Is this question asked at entry level?
It is marked Easy, so it suits engineers who are new to low-level design interviews. It is also a good warm-up before harder questions.
What should I cover first?
Start with the use cases and the core entities, then the responsibilities of each one. Agree on scope with the interviewer before you design anything.
Can I practise it for free?
It is a premium question. Sign up and unlock it once for 10 credits; it then stays unlocked. When you finish, Lala, your personalized AI mentor, can review your design for 30 credits.

Related questions

Updated · Written by the SevyDevy team

Premium questionSign up free, then unlock it