A retailer sells 2 million products from 40 warehouses. Product pages show whether an item is in stock and roughly how many are left, which means about 20,000 availability reads per second at peak. Checkout reserves stock at a specific warehouse, up to 1,500 reservations per second during promotions, and a popular item may receive hundreds of orders in the same second. Warehouses send stock updates when deliveries arrive or items are found damaged. The business must never sell stock it does not have, but reservations for abandoned baskets should not lock items forever.
Functional requirements
Show availability per product, optionally per warehouse
Reserve stock at checkout and confirm or release the reservation
Expire reservations that are not confirmed within 15 minutes
Apply stock adjustments from warehouses (deliveries, damage, returns)
Publish stock-level changes to search, pricing and alerting systems
Non-functional requirements
No overselling: confirmed reservations never exceed physical stock
Availability reads return in under 150 ms at p95; slight staleness is acceptable on product pages
Reservations on a hot item stay correct under hundreds of concurrent requests
Every stock change is auditable
Constraints and scale
2 million products across 40 warehouses (about 30 million stock rows)
20,000 availability reads per second at peak
1,500 reservations per second at peak, concentrated on a few hundred hot items
You will practise
Prevent lost updates with conditional writes or row-level locking in a transactional store
Separate a strongly consistent write path from a cached, eventually consistent read path
Model reservations with expiry and publish changes with an outbox
Show 3 hints
Two checkouts read 'one left' at the same time. What makes exactly one of them succeed?
Does a product page need the exact count, or just 'in stock' versus 'only a few left'?
How will reservations for abandoned baskets be released without a person noticing?