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.