easy

Design a Vending Machine

Design a vending machine that can dispense various items. The system should manage inventory, handle different types of payments (coins, cash, cards), and provide maintenance alerts.

Suggested time: 45 minutes

Loading the workspace...

About this problem

A vending machine sounds trivial: insert money, press button, get snack. But underneath, the system must manage concurrent state transitions (what happens if someone inserts coins and the power flickers?), pluggable payment methods, real-time inventory tracking, and safe change-making. The design challenge is modeling these state-dependent behaviors cleanly so that invalid operations are impossible at compile time, not caught by runtime checks scattered across the codebase.

What your design needs to cover

  • Display Available Products

  • Accept Multiple Payment Methods

  • Dispense Product and Change

  • Cancel Transaction

  • State-Dependent Behavior

Key challenges the editorial covers

Learn from other designs

Related problems

Guides