🖥️
Sunil Notebook
Interview Preparation
  • 📒Notebook
    • What is this about ?
  • System Design
    • 💡Key Concepts
      • 🌐Scalability
      • 🌐Latency Vs Throughput
      • 🌐Databases
      • 🌐CAP Theorem
      • 🌐ACID Transactions
      • 🌐Rate limiting
      • 🌐API Design
      • 🌐Strong Vs eventual consistency
      • 🌐Distributed tracing
      • 🌐Synchronous Vs asynchronous Communication
      • 🌐Batch Processing Vs Stream Processing
      • 🌐Fault Tolerance
    • 💎Building Blocks
      • 🔹Message
      • 🔹Cache
      • 🔹Load Balancer Vs API Gateway
    • 🖥️Introduction to system design
    • ⏱️Step By Step Guide
    • ♨️Emerging Technologies in System Design
    • ☑️System design component checklist
      • 🔷Azure
      • 🔶AWS
      • ♦️Google Cloud
    • 🧊LinkedIn feed Design
    • 🏏Scalable Emoji Broadcasting System - Hotstar
    • 💲UPI Payment System Design
    • 📈Stock Broker System Design - Groww
    • 🧑‍🤝‍🧑Designing Instagram's Collaborative Content Creation - Close Friends Only
    • 🌳Vending Machines - Over the air Systems
    • Reference Links
  • DSA
    • Topics
      • Introduction
      • Algorithm analysis
        • Asymptotic Notation
        • Memory
      • Sorting
        • Selection Sort
        • Insertion Sort
        • Merge Sort
        • Quick Sort
        • Quick'3 Sort
        • Shell Sort
        • Shuffle sort
        • Heap Sort
        • Arrays.sort()
        • Key Points
        • Problems
          • Reorder Log files
      • Stacks and Queues
        • Stack Implementations
        • Queue Implementations
        • Priority Queues
        • Problems
          • Dijkstra's two-stack algorithm
      • Binary Search Tree
        • Left Leaning Red Black Tree
          • Java Implementations
        • 2-3 Tree
          • Search Operation - 2-3 Tree
          • Insert Operation - 2-3 Tree
        • Geometric Applications of BST
      • B-Tree
      • Graphs
        • Undirected Graphs
        • Directed Graphs
        • Topological Sort
      • Union Find
        • Dynamic Connectivity
        • Quick Find - Eager Approach
        • Quick Find - Lazy Approach
        • Defects
        • Weighted Quick Union
        • Quick Union + path comparison
        • Amortized Analysis
      • Convex Hull
      • Binary Heaps and Priority Queue
      • Hash Table vs Binary Search Trees
  • Concurrency and Multithreading
    • Introduction
    • Visibility Problem
    • Interview Questions
    • References
      • System design
  • Design Patterns
    • ℹ️Introduction
    • 💠Classification of patterns
    • 1️⃣Structural Design Patterns
      • Adapter Design Pattern
      • Bridge Design Pattern
      • Composite Design Pattern
      • Decorator Design Pattern
      • Facade Design Pattern
      • Flyweight Design Pattern
      • Private Class Data Design Pattern
      • Proxy Design Pattern
    • 2️⃣Behavioral Design Patterns
      • Chain Of Responsibility
      • Command Design Pattern
      • Interpreter Design Pattern
      • Iterator Design Pattern
      • Mediator Design Pattern
      • Memento Design Pattern
      • Null Object Design Pattern
      • Observer Design Pattern
      • State Design Pattern
      • Strategy Design Pattern
      • Template Design Pattern
    • 3️⃣Creational Design Patterns
      • Abstract Factory Design Pattern
      • Builder Design Pattern
      • Factory Method Design Pattern
      • Object Pool Design Pattern
      • Prototype Design Pattern
      • Singleton Design Pattern
    • Java Pass by Value or Pass by Reference
  • Designing Data-Intensive Applications - O'Reilly
    • Read Me
    • 1️⃣Reliable, Scalable, and Maintainable Applications
      • Reliability
      • Scalability
      • Maintainability
      • References
    • 2️⃣Data Models and Query Languages
      • Read me
      • References
    • Miscellaneous
  • Preparation Manual
    • Disclaimer
    • What is it all about?
    • About a bunch of links
    • Before you start preparing
    • Algorithms and Coding
    • Concurrency and Multithreading
    • Programming Language and Fundementals
    • Best Practices and Experience
  • Web Applications
    • Typescript Guidelines
  • Research Papers
    • Research Papers
      • Real-Time Data Infrastructure at Uber
      • Scaling Memcache at Facebook
  • Interview Questions
    • Important links for preparation
    • Google Interview Questions
      • L4
        • Phone Interview Questions
      • L3
        • Interview Questions
      • Phone Screen Questions
  • Miscellaneous
    • 90 Days Preparation Schedule
    • My Preparation for Tech Giants
    • Top Product Based Companies
  • Links
    • Github
    • LinkedIn
Powered by GitBook
On this page
  • Introduction
  • Problem Statement
  • Scope and requirements
  • Identify Functional and Non-Functional Requirements
  • Envelope calculations
  • High Level Design
  • Trade-offs and Considerations
  • References

Was this helpful?

Edit on GitHub
  1. System Design

Vending Machines - Over the air Systems

Introduction

What are over the air update systems?

Over the air update systems are also known as the over the air programming, it is an update to the embedded system delivered though a wireless network.

There is also a term called FOTA - Firmware over the air. Updating the firmware over the air is called FOTA.

Before OTA, embedded systems were flashed only through direct physical access or wired connections.

Here are some examples from Bing Copilot:

  1. Smartphones: Both iOS and Android devices receive OTA updates for their operating systems, apps, and security patches.

  2. Automobiles: Modern cars, especially those from manufacturers like Tesla and BMW, receive OTA updates for their infotainment systems, navigation, and even firmware updates for vehicle components.

  3. Internet of Things (IoT) Devices: Smart home devices, such as thermostats, security cameras, and smart speakers, often receive OTA updates to improve functionality and security.

  4. Telecommunications Equipment: Network devices like routers and modems receive OTA updates to enhance performance and security

Vending Machines fall into the category of IOT devices. These machines are part of the broader IoT ecosystem, where devices are connected to the internet and can communicate with each other and with central systems to receive updates, manage inventory, and enhance functionality.

During the interview, please follow the below steps:

🔹 Understand the Problem 🔸 Define the Scope and Requirements 🔹 Identify Functional and Non-Functional Requirements 🔸 High-Level System Design 🔹 Component Design and Interaction 🔸 Scalability and Reliability 🔹 Security Considerations 🔸 Monitoring and Maintenance 🔹 Trade-offs and Considerations

Problem Statement

Design a vending machine that can dispense products upon receiving the payment

Key considerations are product selection, payment processing, dispensing mechanism and inventory management.

Below are the list of questions to ask yourself:

  • What is the primary goal ?

  • Who are the users ?

  • what are the key use cases ?

Scope and requirements

Functional requirements:

  • Based on the inventory management, display the available products in the machine and show the products and prices in the app after scanning the inventory management.\

  • Accept Multiple payment methods

  • Dispense the selected products after successful payment

  • Track and manage inventory in real-time.

Non-Functional requirements:

High Availability and reliability

Secure transactions

Remote Monitoring capability

Identify Functional and Non-Functional Requirements

Functional: Payment processing, product selection, dispensing mechanism, and inventory updates.

Non-Functional: System availability, payment security, ease of use, and remote monitoring.

Envelope calculations

Data Assumptions:

Number of vending machines: 200

Number of different products: 25 per vending machine

Transactions per machine per hour: 20

Average size of each transaction: 1KB

Average size of product inventory: 1KB

Total number of transactions per hour = 200 * 20 = 4000

Transactions across machines = 96,000

High Level Design

  1. Inventory Management service: As the name suggests to maintain the inventory across all the 200 vending machines

  2. Product Real time view service: Display variety of products and their prices in real time. This will be integrated in the mobile app to show the products after scanning the machine.

  3. Payment Processing service: As the name suggests to process and secure the payment integration with external gateways

  4. Dispensing service: Communicates with hardware to dispense the items based on the payment status.

  5. Remote Monitoring service: Provides the real time monitoring of all the machines, including the inventory management, machine health, transaction status

  6. Transaction logging service: Logs all the transactions including payment successful or failed attempts. This is also responsible for maintaining the history of all interaactions and transactions.

  7. Identity Management service: Manages the user authentication for mobile app access.

  8. Analytics service: Provides insights into product sales, machine usage and user behaviour. Supports business intelligence for restocking and few marketing insights.

Trade-offs and Considerations

CAP theorem states that in any distributed system, it is impossible to simultaneously guarantee all three of the following properties:

  1. Consistency (C): Every read receives the most recent write or an error.

  2. Availability (A): Every request (read or write) receives a response, without guarantee that it contains the most recent write.

  3. Partition Tolerance (P): The system continues to operate despite network partitions (communication breaks between nodes).

CAP Theorem

For the vending machine system, the CAP theorem applies as follows:

1. Partition Tolerance:

Partition tolerance is a necessary property for any distributed system, especially when dealing with physical vending machines that may be located in different regions or connected over potentially unreliable networks. The system must be able to handle temporary network failures without crashing. This is non-negotiable in distributed systems.

2. Consistency vs. Availability:

Consistency: Ensuring that every read reflects the most recent write is crucial for certain operations, like maintaining accurate inventory levels and ensuring that payments are correctly processed. However, in cases where the network is partitioned, insisting on consistency might mean that the system cannot respond to requests (leading to unavailability).

Availability : Ensuring that the vending machine always responds to user requests (e.g., dispensing a product, accepting payments) is also critical. If the system prioritizes availability, it might serve slightly stale data or accept payments even if there is a temporary inconsistency in the inventory count.

Applicable Choices:

Given the nature of a vending machine system, it must balance consistency and availability but can only fully guarantee one under partition conditions:

In a Scenario Favoring Availability:

The system ensures that the vending machine remains operational and responsive even if it cannot guarantee that the inventory count is perfectly accurate. This might mean accepting a payment even if the inventory count hasn't been synchronized across all nodes, risking an "out of stock" situation that needs to be rectified later.

This is crucial because vending machines need to be always available to users, especially in locations where network connectivity might be unreliable.

In a Scenario Favoring Consistency:

The system could enforce strict inventory synchronization, ensuring that users are never charged for products that are not available. This might come at the cost of availability, where the machine could become temporarily unavailable if the system cannot confirm the latest state due to a network partition.

This might be acceptable in environments where vending machine users expect high reliability in inventory reporting, but it risks frustrating users during network issues.

My recommendation:

For a vending machine system, Partition Tolerance and Availability are often prioritized over strict Consistency. The reasoning is that vending machines need to be operational and responsive to user interactions at all times, even if that occasionally means dealing with slight inconsistencies in inventory data or transaction logs. The system would likely aim for eventual consistency, where data inconsistencies are resolved over time, ensuring that the machine remains available during network issues.

References

PreviousDesigning Instagram's Collaborative Content Creation - Close Friends OnlyNextReference Links

Last updated 9 months ago

Was this helpful?

https://en.wikipedia.org/wiki/Over-the-air_update
https://vendingmachineindia.in/big-basket-vending-machine/
https://www.geeksforgeeks.org/vending-machine-high-level-system-design/
https://www.trio.so/blog/over-the-air-update/
https://jfrog.com/connect/post/ota-updates-for-remote-devices-different-methods-explained/
https://support.toyota.com/s/article/21MM-OvertheAir-Softw-10738?language=en_US
https://www.android.com/auto/
https://www.vendsoft.com/
🌳
Page cover image