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.