Course map

Project 07

Inventory reservation

Concurrency and consistency

Start after Part 8

Key topics 71, 129, 137

Architecture Single service, done rigorously

Brief

The inventory service behind Projects 6 and 16: track stock per SKU, reserve on checkout, confirm on payment, release on timeout or cancellation — correct under heavy concurrency.

Targets

5k reservation attempts/sec on hot SKUs · zero oversells · reservation p99 < 100 ms · expired reservations released within 30 s.

Must cover

  • Overselling prevention — proven under concurrent load (→ 71).
  • Reservation expiry with leases (→ 137).
  • Stock reconciliation — periodic comparison against movements, with correction entries (→ 81).

Design challenges

  1. The core race (→ 71): 100 concurrent buyers, 3 units left. Solve three ways and benchmark: atomic conditional update (UPDATE … WHERE available >= n), SELECT … FOR UPDATE, optimistic versioning with retry.
  2. Reservation expiry (→ 137): holds as leases; the race between expiry and payment confirmation handled explicitly.
  3. Hot-SKU contention: the single-row serialization limit — when sharded counters or slotting become necessary, and their complexity cost (→ 88, 73).
  4. Idempotent reserve, confirm, and release operations for safe retries (→ 38, 116).
  5. A consistency statement per read (→ 129): what the "in stock" badge guarantees vs. the reservation itself — and where stale reads are acceptable.
  6. An audit trail of every stock movement feeding reconciliation (→ 81); evaluate the event-sourced variant honestly and adopt or reject it with reasons (→ 120).

Out of scope

Multi-warehouse allocation and demand forecasting.

Search the guide