← Lessons

quiz vs the machine

Platinum1760

System Design

Inventory Reservation

Holding stock during checkout with expiring reservations to avoid overselling.

6 min read · advanced · beat Platinum to climb

Why reserve at all

Between adding to cart and paying, a shopper needs the stock to still be there. Inventory reservation temporarily holds units so they cannot be sold to someone else mid checkout, without permanently removing them from availability.

Reservations expire

A reservation is a soft hold with a time to live. If the shopper abandons checkout, the hold must expire and return the units to available stock. Without expiry, abandoned carts would leak stock forever.

Confirm or release

  • On successful payment, the reservation is committed, turning a soft hold into a real decrement.
  • On failure or timeout, the reservation is released and stock returns to available.

This is a two phase pattern: reserve, then confirm or cancel.

Correctness under concurrency

The reserve operation must be atomic against available stock so two checkouts cannot both reserve the last unit. Expiry is best handled by storing an expiry timestamp and sweeping or by a key with a native time to live.

Key idea

Reserve stock as an atomic, expiring soft hold, then commit on payment or release on timeout to prevent both overselling and leaked stock.

Check yourself

Answer to earn rating on the learn ladder.

1. Why must inventory reservations expire?

2. What does committing a reservation mean?

3. Why must the reserve operation be atomic?