Traffic estimates
Bandwidth Estimates
Storage estimates
add_items(company, array_of_items and their count)
update_item(company, item, change)
place_order(company, array of items and the requested count)
We will most likely have a company table and an items table, hence there exists a relation between the tables, we can use a SQL database. However, SQL tables are not exactly scalable, we want to use a database that can scale, hence a documentDB like MongoDB would be useful.
Client -> backend server -> MongoDB
The most important detail here is how can we give real time updates when there are a huge number of changes per second? Whenever an update_item API is called, what we dont want to do is to make the change in DB and then return the results to the user immediately. this will cause high latencies and overwork the database. What we can do instead is to maintain an in memory storage like a HashMap with (company, item) as the key and (count) as the value. Whenever update_item is called, the HashMap will be updated, after a certain time quantum (2 seconds) it dumps the data into the database and return the updates to the user. This is useful because this in memory HashMap acts like a buffer that will track the changes quickly instead of querying the database every time a change is made (which is a slow process), this actually also allows for better user experience, this is because if the results are being returned too quickly, sometimes the user might be confused by the quick changing numbers.
What happens then if the server crashes before the data is dumped into the database? this is where back up servers are needed. The backup severs will check if data has been dumped into the database, if not, it might be an. indication that the main sever has malfunctioned. then the backup server will dump it instead. This allows for data reliability.
After each time data is dumped into the dtaabase, the server will also check if there are any items with a count below 20, if so the server will send an alert to the user.
Explain any trade offs you have made and why you made certain tech choices...
Try to discuss as many failure scenarios/bottlenecks as possible.
Food can expire, hence it would be useful if this inventory system kept track of items that can expire, if there are expiring foods, the server will send an alert as well