Design an Inventory Management System
Understanding the Problem
📦 What is an inventory management system? An inventory management system keeps track of how many units of each product a business has, where they are, and what state they're in: sellable, reserved for an order, damaged, in transit. Every time stock moves (a truck is unloaded, an order is picked, a customer returns something) the system records it. The rest of the business, from the product page to purchasing, relies on those numbers being right.
In an interview this usually shows up as the system behind a large retailer: a storefront that needs to know what it can sell, warehouses that move stock around, and an operations team that needs to trust the counts.
Functional Requirements
Ask what the system is for. A warehouse management system (WMS) cares about bins, pick paths and labor. We'll design the inventory system of record that sits between the storefront and the warehouses.
Core Requirements
- Warehouse systems should be able to record stock movements: receiving, picking, shipping, transfers between locations, and adjustments for damage, loss and cycle counts.
- The storefront should be able to read how many units of a SKU are available to sell, overall and per location.
- The order system should be able to reserve stock at checkout, then either consume the reservation when the order ships or release it if the order is cancelled.
- Returned items should go back into stock, or to a damaged or refurbished state, depending on their condition.
Below the line (out of scope)
- Warehouse floor operations: bin slotting, pick paths, labor planning.
- Demand forecasting and automatic purchase orders (we'll emit low-stock alerts, nothing more).
- Accounting valuation of inventory (FIFO, weighted average cost).
Non-Functional Requirements
Get numbers from your interviewer. We'll assume 100M SKUs across 500 locations (fulfillment centers, stores and returns centers). A SKU is stocked at about 10 locations on average, so there are about 1B SKU-location balances.
Core Requirements
- The system should never let the storefront sell more units than are physically available, beyond a small, deliberate safety margin. Reservations need strong consistency.
- The system should keep a complete, immutable history of every movement, so any balance can be explained and audited.
- The system should handle on the order of 20k reservations per second at sale-day peaks, with reservation latency under 100 ms.
- Availability reads should handle 200k reads per second and may be a few seconds stale.
- The system should tolerate warehouse devices that go offline and send events late, duplicated or out of order.
Below the line (out of scope)
- Multi-region active-active writes. Each SKU's balances have one home region.
- Real-time location tracking of trucks between warehouses (in-transit stock is a balance, not a GPS feed).
The back-of-the-envelope:
- Balances. 1B rows × ~100 bytes = ~100 GB. Small enough for a sharded relational database, and hot rows fit in memory.
- Movements. About 200M a day (each order produces a reservation, pick, pack and ship event, plus receipts, transfers and counts). That's ~2,300/s on average and ~12k/s at peak. At ~200 bytes each, that's 40 GB a day, or ~15 TB a year.
- Reservations. 20M orders a day × 3 lines = 60M a day, ~700/s average, with sale-day peaks around 20k/s.
Two things fall out of this. The write rate across the whole system is modest; a sharded database handles it. But writes are not spread evenly: a single popular SKU on a sale day can get thousands of reservations a second on one row. And the movement history grows forever, so it needs its own long-term home.
Interviewers often ask "what is the inventory count?" as if it's one number. It isn't. A SKU at a location has on-hand, reserved, damaged, inbound and in-transit quantities, and "available to sell" is derived from them. Getting this model right early makes every later question easier.