List functional requirements for the system (Ask the chat bot for hints if stuck.)...
Users can choose the product and its number in the vending machine.
Users can pay for the product with a bank card, cash, Paypal, the cryptocurrency and get the choosen product.
If users choose a product number that isn't available, the vending machine shows an error.
If users choose the product and there is a blackout, the vending machine shows an error.
If users choose the product and there is an internet connection issue, the vending machine shows an error.
Estimate the scale of the system you are going to design...
10 million vending machines need about 100 GBytes.
Define what APIs are expected from the system...
Endpoint: POST /pay
Description: This API starts paying for the selected products in a vending machine.
Payload: { "vendingMachineId": "string", "paymentMethod": "string" // Values: {"cash", "card"},
"paymentKey": "string"//encrypted card information,
"productType":"string",
"price":"double", "productAmount":"int"
{"oriderId":"string", "order":{ ["productId": "string", "productName": "string", "expirationDate" :"timestamp",
"price":"double","amount":"int"]}
}
}
Response:
{ "success": true, "message": "Status updated successfully." }
{"success":false,"message":"Not enough money","Card information is invalid","Connection broken"}
2. Get the product list from the vending machine
Endpoint: GET /products/<vendingMachineId>
Description: This API returns the list of products the user can buy in the given vending machine.
Response:
{
["productId": "string", "productName": "string", "expDate" :"timestamp", "updateDate":"timestamp",
"price": "double", "amount": "int"]
}
Admin API:
Endpoint: POST /vendingMachine
Description: This API creates a new vending machine.
Payload:
{"namee":"string", "location": GeoData, "createdAt":timestamp}
Response:
{"vendingMachineId":"string", "location": GeoData,"createdAt": timestamp }
Endpoint: GET /vendingMachines
Description: This API returns the list of vending machines.
Response:
{
[{"vendingMachineId":"string","location": GeoData,"createdAt":timestamp }]
}
Defining the system data model early on will clarify how data will flow among different components of the system. Also you could draw an ER diagram using the diagramming tool to enhance your design...
Below is a detailed schema using PostgresSQL.
VendingMachineProduct Table
VendingMachine Table
This table has information about the vending machines that are installed.
This table has information about the vending machine orders.
OrderDetail Table
This table has information about the specific vending machine orders.
VendingMachine ||--o{ VendingMachineProduct : has
Order ||--o{ OrderDetail : has
API Gateway
Payment service
Order service
Product List service
We'll examine the scenario:
Selecting and paying for the product from the vending machine.
This flow describes what happens when a user selects the product.
Sequence of Events:
Purpose: The Web Server handles all incoming API requests for updating and retrieving user statuses.
Key Responsibilities:
Scalability:
Technologies:
Purpose: The Cache Layer provides fast access to frequently accessed data, such as user statuses, to reduce latency and database load.
Key Responsibilities:
Scalability:
Technologies:
Purpose: Manages the distribution of real-time status updates to other clients and services.
Key Responsibilities:
Scalability:
Technologies:
Explain any trade offs you have made and why you made certain tech choices...
Try to discuss as many failure scenarios/bottlenecks as possible.
What are some future improvements you would make? How would you mitigate the failure scenario(s) you described above?