100 purchases a day -> 365 000 purchases a year
We will keep history for last 1 year
Item Table:
itemID -> 4 bytes
Price -> 4 bytes
ItemName -> 21 bytes
ImageKey -> 4 bytes
Bytes per row: 33 bytes
Would not need to worry about capacity of item DB
Transaction Table:
TransactionID -> 4 bytes
itemID -> 4 bytes
Price -> 4 bytes
ItemName -> 21 bytes
Success -> 1 Bytes
Bytes per row: 34 bytes per row
365 000 * 34 = ~12.5MB per year
Would not need to worry about capacity of transaction DB
Do not need to worry about scaling horizontally for now
External Endpoints:
GET:
POST:
Internal Endpoints:
POST:
SQL DB -> MySQL
Transactions:
Items:
Vending machine display will not be changed much, we can assume that most requests will be requests to pay for a certain item
We will use Stripe third party API to handle credit/debit card, there should be some hardware in the front-end to calculate actual cash being used to pay
To display the items and the prices for the items, we will have a GET endpoint to grab each item
To Display UI:
GET request to get items -> Client side logic to display items
Pay for item:
POST request to pay -> server side authenticates and approves payment through Stripe
Transactions -> Transaction table includes itemID, time of transaction, price (include price separately in case item price changes), success
When user sends POST request to pay, we store the transaction in transaction table (will store both failed and successful transactions)
Can add extra layer of security -> If user fails 3 times then we will autofail -> Stripe probably has a response for if user is locked out for the day -> server side will use that response to display to client side
Explain any trade offs you have made and why you made certain tech choices...
Too many people buying at once, will be write heavy
What are some future improvements you would make? How would you mitigate the failure scenario(s) you described above?