Coffee Vending Machine – Low Level Design Interview Practice
Practise the Coffee Vending Machine low level design problem the way an LLD round actually runs. You are asked for requirements first, then a class model, and then to extend the design when a new requirement lands part way through – the follow-up that separates a design that was memorised from one that was understood.
The round checks the things interviewers grade: whether your classes carry single responsibilities, whether you reached for a design pattern or reinvented one, whether the design absorbs a new requirement without rewriting what exists, and whether you can explain a trade-off out loud. Feedback covers class modelling, SOLID principles, use of patterns, extensibility and communication.
What this question is really testing
A compact three-pattern problem: state for the brew cycle, strategy for recipes, and ingredient checks that fail before taking payment.
Requirements to establish first
- Offer several beverages, each with its own ingredient quantities.
- Check ingredient availability before starting, and report what is missing.
- Brew one beverage at a time, moving through select, brew, dispense.
- Refill ingredients and report low levels.
- Handle a selection made while a brew is already running.
Core classes
- CoffeeMachine – Current state, ingredient inventory and the beverage menu.
- MachineState – Idle, Selecting, Brewing, Dispensing, NeedsRefill.
- Beverage / Recipe – A named drink and the ingredient quantities it consumes.
- Ingredient / Inventory – Quantities held, decremented on a successful brew.
- BrewingStrategy – Espresso, filter and latte differ in method, not only in ingredients.
Design patterns that apply
- State – A selection made mid-brew must be refused, and the state object is what refuses it.
- Strategy – Brewing method per beverage type.
- Factory – Building a beverage from a menu code, so adding a drink is a registration rather than a new branch.
Follow-up questions to expect
- Two ingredients are low and a drink needs both. Do you report one failure or all of them?
- Add a customisable drink - extra shot, oat milk. Does Recipe survive, or do you need a Decorator?
- Make the machine brew two drinks at once. What in your state model breaks?
Where candidates lose marks
- Checking ingredients after taking payment.
- Decrementing ingredients at selection rather than on a completed brew.
- A boolean isBrewing instead of a state, which cannot express NeedsRefill.