Open In App

Vending Machine: High Level System Design

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.



Important Topics for High-Level Design of Vending Machine

Vending machine’s requirements:

Lifecycle of a Vending Machine

Lifecycle of Vending Machine

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



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

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

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

Out of Stock

The user asks for some item that is out of stock

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.


Article Tags :