← Lessons

quiz vs the machine

Platinum1820

System Design

Distributed Inventory Consistency Deep Dive

Counting stock correctly across shards and regions.

6 min read · advanced · beat Platinum to climb

The hard part

A single counter is easy. Inventory becomes hard when stock for one product lives across shards, warehouses, or regions and reads must stay close to buyers while writes stay correct.

Strategies

  • Single owner per item: route every write for a product to one authoritative shard. Reads can be cached and slightly stale.
  • Partitioned pools: split a product into per warehouse buckets, each its own strongly consistent counter, and sum sellable across buckets.
  • Lease and reconcile: a region borrows a block of units under a lease, sells locally, and returns the unused remainder.

Consistency choices

  • Strong consistency on the counter avoids oversell but adds cross region latency.
  • Eventual consistency speeds reads but needs a buffer so displayed stock never undercounts into oversell.
  • A periodic reconciliation job compares ledgers and corrects drift.

The safe default is one authoritative owner per item for writes, with stale tolerant reads and a reconciliation pass that heals divergence.

Key idea

Make writes for each product converge on one authoritative owner, allow stale reads with a safety buffer, and run reconciliation to correct drift across the distributed pool.

Check yourself

Answer to earn rating on the learn ladder.

1. Why route all writes for a product to one owner shard?

2. What does a reconciliation job provide?

3. Why add a buffer to eventually consistent displayed stock?