Design Coffee Vending Machine

Difficulty: Easy Source: awesome-low-level-design

Requirements

  1. Support espresso, cappuccino, latte
  2. Each type has price and recipe
  3. Display menu with prices
  4. Choose coffee and submit payment
  5. Dispense coffee and return change
  6. Track ingredient inventory
  7. Handle concurrent requests

Class Diagram

Class Diagram


Classes, Interfaces and Enumerations

Class/Interface Description
Coffee name, price, recipe (ingredient-to-quantity map)
Ingredient name, quantity; synchronized update method
Payment amount paid
CoffeeMachine Singleton; menu, ingredients, dispensing

Design Patterns Used

Pattern Application
Singleton CoffeeMachine has a single instance managing all operations

Code Implementations

Language Source Code
Java View on GitHub
Python View on GitHub
C++ View on GitHub
C# View on GitHub
Go View on GitHub