·

System Design Deep Dive - 06 How Amazon Handles Inventory Sync

Post by ailswan May. 26, 2026

中文 ↓

🎯 How Amazon Handles Inventory Sync


1️⃣ Core Inventory Framework (Staff-Level)

When discussing an Amazon-like inventory system, I frame it as:

  1. Inventory source of truth
  2. Available vs reserved vs sold stock
  3. Reservation lifecycle
  4. Warehouse and seller updates
  5. Event-driven propagation
  6. Reconciliation and correction
  7. Oversell protection
  8. Trade-offs: correctness vs latency vs availability vs throughput

2️⃣ Core Problem

Inventory is deceptively hard because many systems read and write stock:

The system must avoid overselling while still serving high read traffic.


👉 Interview Answer

I would not model inventory as one mutable number. I would model it as a state machine with on-hand, reserved, sold, released, returned, and adjusted quantities. This makes checkout safer and makes reconciliation possible when distributed systems drift.


3️⃣ Inventory State Model

Common fields:

on_hand
reserved
available = on_hand - reserved - safety_stock
sold
returned
damaged

Important invariant:

available >= 0

4️⃣ Reservation Flow

User starts checkout
        ↓
Reserve inventory
        ↓
Payment attempt
        ↓
If payment succeeds: convert reservation to sold
If payment fails: release reservation
If timeout: expire reservation

👉 Interview Answer

Reservation protects the checkout path. Instead of decrementing final stock immediately, the system creates a temporary hold with a TTL. If payment succeeds, the hold becomes sold inventory. If payment fails or times out, the hold is released.


5️⃣ Consistency Boundaries

Use stronger consistency for:

Use eventual consistency for:


👉 Interview Answer

I would use strong consistency in the checkout reservation path because overselling directly hurts customers. For product pages and search, eventual consistency is usually acceptable if we revalidate before checkout.


6️⃣ Event-Driven Sync

Inventory Change
        ↓
Inventory Event
        ↓
Message Bus
        ↓
Search Index / Catalog / Warehouse / Analytics

Events:


7️⃣ Reconciliation

Why reconciliation is necessary:

Reconciliation compares:

Inventory Ledger
vs
Warehouse Physical Count
vs
Order State
vs
Seller Feed

👉 Interview Answer

At scale, drift is unavoidable. The system needs a durable inventory ledger and reconciliation jobs that compare computed inventory with warehouse or seller truth, then create correction events instead of silently mutating state.


8️⃣ Oversell Protection

Patterns:


9️⃣ Staff-Level Trade-offs

Decision Benefit Cost
Strong checkout reservation Prevents oversell Adds latency and contention
Eventual read models High read scale Temporary stale availability
Safety stock Reduces oversell May hide sellable inventory
Ledger-based model Auditable and correctable More storage and complexity
Reconciliation jobs Repairs drift Operational overhead

🔟 Failure Handling

Important failures:

Protections:


中文部分

中文速记

一句话

Amazon Inventory 不能当成一个 stock number,而要设计成 available、reserved、sold、released、returned 的库存状态机。


背诵要点


中文面试回答

我不会把库存设计成一个简单的可变数字。 更好的做法是把库存建模成状态机,比如 on-hand、reserved、sold、released、returned 和 adjusted。 商品详情页和搜索页可以使用最终一致的库存视图,但 checkout 路径必须使用强一致的 reserve 操作,避免超卖。

用户进入 checkout 后,系统创建一个带 TTL 的 reservation。 如果支付成功,reservation 转成 sold。 如果支付失败、用户放弃或超时,reservation 被释放。 所有库存变化都应该写入 durable ledger,并发出 inventory events 给下游系统。

Staff 级重点是:分布式库存一定会出现漂移。 仓库、卖家、退货、取消和人工调整都会异步发生,所以系统必须有 reconciliation job,把库存 ledger、订单状态、仓库实物数量和卖家 feed 做对账。


✅ Final Interview Answer

An Amazon-like inventory sync system should be designed around reservations and an inventory ledger. Product pages and search can use eventually consistent availability, but checkout must reserve stock using a strongly consistent operation. The reservation has a TTL and transitions to sold only after payment succeeds. If checkout fails or expires, the reservation is released.

Inventory changes should emit events to update catalog, search, warehouse, and analytics systems. Because many systems update inventory asynchronously, reconciliation is required. At staff level, the key insight is that inventory correctness comes from explicit state transitions, idempotent operations, and continuous reconciliation, not from trusting a single cached stock number.

Implement