Course contentsShow
← System Design
Lesson 499 of 1,91914. CAP TheoremFree lesson

Inventory Management (CP)

Why inventory systems need strong consistency to prevent overselling and maintain accurate stock counts.

Inventory Management (CP)

What you'll learn: Why inventory systems must prioritize consistency over availability to prevent overselling and maintain accurate stock counts.

When you're managing inventory for an e-commerce platform or warehouse, every product has a finite quantity. If your system allows customers to purchase items based on stale or inconsistent data, you'll end up overselling—promising products you don't actually have in stock.

Why Inventory Demands Strong Consistency

Think of inventory like a shared bank account: if two people try to withdraw the last $100 simultaneously without coordination, both withdrawals might succeed, leaving you overdrawn. Similarly, if two customers try to buy the last item in stock, you need a system that ensures only one purchase succeeds.

An AP system (prioritizing availability) might allow both customers to complete their purchase during a network partition, discovering the problem only when you try to fulfill orders. This creates customer frustration, refund overhead, and reputation damage.

A CP system (prioritizing consistency) instead refuses to complete a purchase unless it can guarantee the inventory count is accurate and up-to-date. If the system cannot confirm the stock level due to a partition, it will block the purchase or return an error rather than risk overselling.

The Trade-off in Practice

During a network partition, a CP inventory system might show "unavailable" or delay purchases temporarily. This temporary unavailability is preferable to the alternative: angry customers receiving cancellation emails after they've already paid for items that don't exist.

The consistency guarantee ensures that when you decrement inventory from 1 to 0, no other transaction can also decrement that same item—maintaining accurate stock levels at all times.

Key Takeaway: Inventory management systems choose CP because preventing overselling through strong consistency is more critical than maintaining availability during network failures—you can't ship products you don't have.