← Lessons

quiz vs the machine

Gold1380

System Design

The Inventory Management System

Tracking how many units exist so you never oversell or hide available stock.

5 min read · core · beat Gold to climb

The job of inventory

The inventory system answers one question for every product: how many units are available to sell right now. Get it wrong and you either oversell stock you do not have or hide stock you could be selling.

On hand versus available

  • On hand is the physical count in warehouses.
  • Reserved is units held for carts and unconfirmed orders.
  • Available to sell equals on hand minus reserved.

Exposing only available to sell prevents two shoppers from buying the last unit.

Consistency matters

Inventory writes must be atomic. Decrementing a count needs a transaction or a conditional update so two concurrent buyers cannot both succeed on the final unit. This is the classic race condition that causes overselling.

Scaling reads

Reads of stock counts are far more frequent than writes, so cache availability for display, but always re check the authoritative count at the moment of reservation or order placement.

Key idea

Track on hand and reserved separately, expose available to sell, and make the final decrement atomic to avoid overselling.

Check yourself

Answer to earn rating on the learn ladder.

1. What does available to sell equal?

2. Why must the inventory decrement be atomic?

3. How should frequent stock display reads be handled?