Skip to content
geeksforgeeks
  • Tutorials
    • Python
    • Java
    • Data Structures & Algorithms
    • ML & Data Science
    • Interview Corner
    • Programming Languages
    • Web Development
    • CS Subjects
    • DevOps And Linux
    • School Learning
    • Practice Coding Problems
  • Courses
    • DSA to Development
    • Get IBM Certification
    • Newly Launched!
      • Master Django Framework
      • Become AWS Certified
    • For Working Professionals
      • Interview 101: DSA & System Design
      • Data Science Training Program
      • JAVA Backend Development (Live)
      • DevOps Engineering (LIVE)
      • Data Structures & Algorithms in Python
    • For Students
      • Placement Preparation Course
      • Data Science (Live)
      • Data Structure & Algorithm-Self Paced (C++/JAVA)
      • Master Competitive Programming (Live)
      • Full Stack Development with React & Node JS (Live)
    • Full Stack Development
    • Data Science Program
    • All Courses
  • System Design Tutorial
  • What is System Design
  • System Design Life Cycle
  • High Level Design HLD
  • Low Level Design LLD
  • Design Patterns
  • UML Diagrams
  • System Design Interview Guide
  • Scalability
  • Databases
Open In App
Next Article:
Vending Machine: High Level System Design
Next article icon

Vending Machine: High Level System Design

Last Updated : 04 Jan, 2024
Comments
Improve
Suggest changes
Like Article
Like
Report

Vending machines which are a common thing to be seen in shopping malls or metro stations, kind of operate by themselves. It's different from other systems since it is not a distributed system used by millions of people. It is concurrently used by one person at a time and may be used by a few thousand people a day. So we won't need features like load balancing and caching that we normally use in a system design.

vending-machine

Important Topics for High-Level Design of Vending Machine

  • Requirements
  • Lifecycle Of A Vending Machine
  • Design of Vending Machine
  • Follow-Ups
  • Scalability

Vending machine's requirements:

  • Ability to select an item.
  • Ability to pay for an item(Ask the interviewer which mode of payment they prefer. In this example, we will stick with cash payment.
  • Dispense the item once payment is made.
  • Notify the owner (serving agent) about inventory data. in case the vending machine runs low on any of the items, the owner can refill that item in the vending machine.

Lifecycle of a Vending Machine



Lifecycle-of-Vending-Machine
Lifecycle of Vending Machine


Below is the step-by-step Lifecycle of the Vending Machine:

  • The first thing that we want to make sure of is that the vending machine is in the ready state.
  • After that, the customer needs to select the item that they want to get and make the required payment for that item, only then will the vending machine dispense the item through a tunnel.
  • In case of transaction failure, the system will revert to its ready state. In terms of payment, since this is a cash-only system, it would be beneficial if the vending machine were able to provide change to the customer.
  • In addition to this, we can add the cancel button to the vending machine to cancel the transaction.

Design of Vending Machine

So in the system design diagram, on one side, we have our user. On the other hand, we have our vending machine which consists of two to three key components. We will split these components:

Item Selection

This component has a mapping of an item to a number so that when we select an item, it knows which item to dispense based on that mapping. We can use a a hashmap for this purpose so that the selected button is mapped to the correct item. We can also store the items in a matrix format with a cards row number suggesting the button the user needs to press to get the corresponding item in that column.

Payment System



3
Payment Gateway


Since as we know we are dealing with cash here the vending machine should be capable of calculating and generating change. We can also include some authentication mechanisms in our payment system to check if the user is using counterfeit currencies.

Dispense order

1

So when a customer selects a particular item, the system should be able to make those physical or mechanical movements to dispense that item to the customer. So the user kind of interacts with many components of the vending machine as a whole and not just a single component. The user interacts with the vending machine using a keypad, which is used to take in all the inputs.

Follow-Ups

Now there could be follow-up questions like the workflow of the system when the user selects something that is in stock and the workflow of the system when the user selects something that is out of stock, below is the explanation of both the cases:

In Stock

When the user selects something that is in stock

  • The item selection knows what item the vending machine has to dispense.
  • After that, it goes to the payment section, where the price of the item is calculated.
  • Then in case the money provided by the user is surplus than the actual price, the change is also calculated by the payments system, and the change is dispensed.
  • After the successful calculation of the payment system, it triggers a notification or a the message of the successful transaction to the "dispensing of the item" which finally dispenses the item to the user.

Out of Stock

The user asks for some item that is out of stock

  • So an out-of-stock message needs to be displayed to the customer.
  • Our item selection kind of deals with these things, it has an inventory counter which stores the count of each item of the vending machine.
  • So it checks if the user asked for an item that is in stock or else sends an error message.

Another follow-up Scenarios:

Consider the case if the user does not pay the right amount of money that is the user pays less than the money that the item asks for. So our payment system has to deal with this scenario too. In case that condition is violated, a transaction failed message should be displayed along with reverting the entered money.

Also, there is another condition where the system runs low in change. So in that case, the system can either cancel the transaction and give the money back to the user without dispensing the item due to low change or ask the user to try and provide the exact amount for the item.

Scalability

If we want to add more features to our vending machine like credit card payment we can create a payment gateway for credit cards in the vending machine thus making our system easily scalable.


Next Article
Vending Machine: High Level System Design

P

pritamauddy25
Improve
Article Tags :
  • Geeks Premier League
  • System Design
  • System-Design
  • Geeks Premier League 2023

Similar Reads

    Most Commonly Asked System Design Interview Problems/Questions
    This System Design Interview Guide will provide the most commonly asked system design interview questions and equip you with the knowledge and techniques needed to design, build, and scale your robust applications, for professionals and newbies Below are a list of most commonly asked interview probl
    2 min read
    How to Crack System Design Interview Round?
    In the System Design Interview round, You will have to give a clear explanation about designing large scalable distributed systems to the interviewer. This round may be challenging and complex for you because you are supposed to cover all the topics and tradeoffs within this limited time frame, whic
    9 min read
    System Design Interview Questions and Answers [2025]
    In the hiring procedure, system design interviews play a significant role for many tech businesses, particularly those that develop large, reliable software systems. In order to satisfy requirements like scalability, reliability, performance, and maintainability, an extensive plan for the system's a
    7 min read
    5 Common System Design Concepts for Interview Preparation
    In the software engineering interview process system design round has become a standard part of the interview. The main purpose of this round is to check the ability of a candidate to build a complex and large-scale system. Due to the lack of experience in building a large-scale system a lot of engi
    12 min read
    5 Tips to Crack Low-Level System Design Interviews
    Cracking low-level system design interviews can be challenging, but with the right approach, you can master them. This article provides five essential tips to help you succeed. These tips will guide you through the preparation process. Learn how to break down complex problems, communicate effectivel
    6 min read

    Chat Applications Design Problems

    Designing Facebook Messenger | System Design Interview
    We are going to build a real-time Facebook messaging app, that can support millions of users. All the chat applications like Facebook Messenger, WhatsApp, Discord, etc. can be built using the same design. In this article, we will discuss the high-level architecture of the system as well as some spec
    9 min read

    Media Storage and Streaming Design Problems

    System Design Netflix | A Complete Architecture
    Designing Netflix is a quite common question of system design rounds in interviews. In the world of streaming services, Netflix stands as a monopoly, captivating millions of viewers worldwide with its vast library of content delivered seamlessly to screens of all sizes. Behind this seemingly effortl
    15+ min read
    Design Dropbox - A System Design Interview Question
    System Design Dropbox, You might have used this file hosting service multiple times to upload and share files or images. System Design Dropbox is a quite common question in the system design round. In this article, we will discuss how to design a website like Dropbox.Important Topics for the Dropbox
    14 min read
geeksforgeeks-footer-logo
Corporate & Communications Address:
A-143, 7th Floor, Sovereign Corporate Tower, Sector- 136, Noida, Uttar Pradesh (201305)
Registered Address:
K 061, Tower K, Gulshan Vivante Apartment, Sector 137, Noida, Gautam Buddh Nagar, Uttar Pradesh, 201305
GFG App on Play Store GFG App on App Store
Advertise with us
  • Company
  • About Us
  • Legal
  • Privacy Policy
  • In Media
  • Contact Us
  • Advertise with us
  • GFG Corporate Solution
  • Placement Training Program
  • Languages
  • Python
  • Java
  • C++
  • PHP
  • GoLang
  • SQL
  • R Language
  • Android Tutorial
  • Tutorials Archive
  • DSA
  • Data Structures
  • Algorithms
  • DSA for Beginners
  • Basic DSA Problems
  • DSA Roadmap
  • Top 100 DSA Interview Problems
  • DSA Roadmap by Sandeep Jain
  • All Cheat Sheets
  • Data Science & ML
  • Data Science With Python
  • Data Science For Beginner
  • Machine Learning
  • ML Maths
  • Data Visualisation
  • Pandas
  • NumPy
  • NLP
  • Deep Learning
  • Web Technologies
  • HTML
  • CSS
  • JavaScript
  • TypeScript
  • ReactJS
  • NextJS
  • Bootstrap
  • Web Design
  • Python Tutorial
  • Python Programming Examples
  • Python Projects
  • Python Tkinter
  • Python Web Scraping
  • OpenCV Tutorial
  • Python Interview Question
  • Django
  • Computer Science
  • Operating Systems
  • Computer Network
  • Database Management System
  • Software Engineering
  • Digital Logic Design
  • Engineering Maths
  • Software Development
  • Software Testing
  • DevOps
  • Git
  • Linux
  • AWS
  • Docker
  • Kubernetes
  • Azure
  • GCP
  • DevOps Roadmap
  • System Design
  • High Level Design
  • Low Level Design
  • UML Diagrams
  • Interview Guide
  • Design Patterns
  • OOAD
  • System Design Bootcamp
  • Interview Questions
  • Inteview Preparation
  • Competitive Programming
  • Top DS or Algo for CP
  • Company-Wise Recruitment Process
  • Company-Wise Preparation
  • Aptitude Preparation
  • Puzzles
  • School Subjects
  • Mathematics
  • Physics
  • Chemistry
  • Biology
  • Social Science
  • English Grammar
  • Commerce
  • World GK
  • GeeksforGeeks Videos
  • DSA
  • Python
  • Java
  • C++
  • Web Development
  • Data Science
  • CS Subjects
@GeeksforGeeks, Sanchhaya Education Private Limited, All rights reserved
We use cookies to ensure you have the best browsing experience on our website. By using our site, you acknowledge that you have read and understood our Cookie Policy & Privacy Policy
Lightbox
Improvement
Suggest Changes
Help us improve. Share your suggestions to enhance the article. Contribute your expertise and make a difference in the GeeksforGeeks portal.
geeksforgeeks-suggest-icon
Create Improvement
Enhance the article with your expertise. Contribute to the GeeksforGeeks community and help create better learning resources for all.
geeksforgeeks-improvement-icon
Suggest Changes
min 4 words, max Words Limit:1000

Thank You!

Your suggestions are valuable to us.

What kind of Experience do you want to share?

Interview Experiences
Admission Experiences
Career Journeys
Work Experiences
Campus Experiences
Competitive Exam Experiences