A coffee vending machine is an automated machine that prepares and dispenses coffee and related beverages (like espresso, cappuccino, or tea) to users with minimal human intervention.
Loading simulation...
Users typically interact with the machine by:
Internally, the machine manages ingredient inventory (coffee powder, water, milk, sugar), tracks user inputs, processes payments, and maintains operational states (e.g., idle, dispensing, out of service).
In this chapter, we will explore the low-level design of a coffee vending machine in detail.
Lets start by clarifying the requirements:
Before starting the design, it's important to ask thoughtful questions to uncover hidden assumptions and better define the scope of the system.
Here is an example of how a conversation between the candidate and the interviewer might unfold:
Candidate: Should the machine support multiple beverage types?
Interviewer: Yes, the machine should support a configurable menu of beverage types like espresso, cappuccino, latte, black coffee, etc.
Candidate: Does the system need to support payment functionality?
Interviewer: Yes, the machine should accept money for the selected beverage, dispense the drink once enough has been inserted, and return any change. Keep it simple, a single integer amount is enough, you do not need to model individual coins or notes.
Candidate: Should the machine allow customization, such as choosing sugar level or milk quantity?
Interviewer: Yes, users should be able to make basic customizations such as choosing sugar and milk levels per beverage.
Candidate: Should the machine track inventory of ingredients like coffee, milk, and sugar?
Interviewer: Yes, it should maintain an internal inventory for all ingredients.
Candidate: How should the system handle situations where some ingredients are unavailable?
Interviewer: The system should notify the user with an appropriate message.
Candidate: Does the machine need to support concurrent user interactions?
Interviewer: A single customer interacts with the machine at a time, so you do not need to coordinate multiple simultaneous orders. The shared inventory can still be touched concurrently though, for example an admin restocking while a drink is being dispensed, so it should stay consistent under concurrent access.
Candidate: Should the machine support an admin interface for restocking and maintenance?
Interviewer: Yes, an admin should be able to view current inventory levels and refill or reset the machine as needed.
With the scope clarified, we can now summarize the core system requirements.