AlgoMaster Logo

Design Coffee Vending Machine

Ashish

Ashish Pratap Singh

medium

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.

Coffee Vending Machine

Users typically interact with the machine by:

  • Selecting a drink from a menu
  • Customizing options (e.g., sugar level, milk type, size)
  • Making payment (coins, cash, card, or digital wallet)
  • Receiving the prepared beverage

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:

1. Clarifying 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:

With the scope clarified, we can now summarize the core system requirements.

1.1 Functional Requirements

  • Support a configurable list of beverage types (e.g., espresso, cappuccino, latte)
  • Allow users to select a beverage and customize basic options such as sugar and milk levels
  • Deduct the appropriate amount of ingredients from inventory after each successful order.
  • Display an appropriate message if a selected beverage cannot be prepared due to insufficient ingredients.
  • Allow an admin to view ingredient levels and perform restocking or maintenance operations.
  • Serve one customer at a time (no concurrency required)

1.2 Non-Functional Requirements

  • Modularity: The system should have clear separation of concerns
  • Extensibility: The design should support adding new drink types, and customizing ingredient mixes
  • Maintainability: The codebase should follow object-oriented principles and allow easy modification or extension
  • User Feedback: The machine should provide clear instructions and status updates to the user throughout the interaction

2. Identifying Core Entities

Premium Content

This content is for premium members only.