← All problems
Dashboard
Courses
Problems
Badges
Theme
Sign inStart free
Problem 045 · Databases and storage

Design an Inventory Service

Medium 50 min

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
  1. Two checkouts read 'one left' at the same time. What makes exactly one of them succeed?
  2. Does a product page need the exact count, or just 'in stock' versus 'only a few left'?
  3. How will reservations for abandoned baskets be released without a person noticing?

Ready to build?

Open the canvas, place your components and explain your decisions. Your draft saves automatically.

Sign in to start

Failure scenarios

  • A limited release locks up one rowA limited-edition trainer goes on sale. 800 checkouts per second target the same product at one warehouse, and reservation latency for that item climbs to several seconds while other items are fine.

Run them from the workspace once your design is in place.