assume 100M DAU, 50% place an order daily, read write ratio is 10:1. Suppose we have 100k items.
TPS
write: 100M / 2 /10^5 = 500 transacptions/s
read: 500 * 10 = 5000
Storage:
Inventory management
Order management
Inventory (partition on id+warehouse_id)
Order (can contain multiple inventory)
OrderInventory
Warehouse
Customer order
customer requests listing of the items interested via order service, order service retrieves the details from inventory service. If the customer places an order, order service calls inventory service to update the database.
Replenish
The replenish service scans the database hourly, if it sees an item is low in stock, it puts a message on the message queue. The workers pull from the queue and invokes order service to place a replenish order against the supplier.
Explain any trade offs you have made and why you made certain tech choices...
We can scale the database by partition the inventory table by id+warehouse_id because the inventory is grouped by locations.
We can consider supporting the hold feature where the item is held for a certain time range after being put to the cart.