Design a vending machine
The interviewer asks you to design the software for a machine that takes coins and sells snacks. Picture a kiosk on a railway platform. You put your coins in the dish on the counter, and the seller leaves them there while she looks in her drawer for your change. She sweeps them into the drawer only once you have your chocolate bar.
It is also asked as "design a snack machine", and the closest other case study is the ATM, which also pays out exact money from a limited stock. The round goes on what each state does, and on where the money is at every moment.
Below is a full 45-minute round on the LLD framework. You are the candidate. At each Guess before you read on, stop and answer first. The full runnable project, with its tests, is a download in Java, JavaScript and Python.
Run the full project
This design as a project you can run, with its tests and a demo. You only need Java 21, Node 24 or Python 3.13. The README says how to run it.
Step 1 · Clarify the requirements and cut the scope
Minutes 0–5 · How this step works
Interviewer: Design a vending machine.
You: Which coins does it take, and does it give change?
Interviewer: $1, 25, 10 and 5 cents. Yes, it gives change from the coins it holds.
You: What if it can't make the change?
Interviewer: You tell me. The buyer must never lose money.
You: What if the buyer changes their mind, or the item gets stuck?
Interviewer: Cancel gives the money back. A sensor reports whether the item dropped.
You: How are prices set, and will that change?
Interviewer: Each slot has a list price. The owner wants promotions next year.
You: Then I'll build insert, select, cancel, and the sensor's two reports. Selling needs stock, enough money and change it can really make. Notes, cards and restocking are out. OK?
Interviewer: Good.