The problem
When a customer adds an item to cart or starts checkout, you often want to hold that unit so it is not sold to someone else while they pay. A reservation is a temporary claim on stock with an expiry.
How reservations work
- Split available stock into on hand, reserved, and sellable where sellable equals on hand minus reserved.
- Create a reservation row with a quantity, an owner, and a time to live.
- A background job or lazy check releases expired reservations back to sellable.
- On payment success the reservation is committed and converts to a real deduction.
Trade offs
- Long reservation windows protect the buyer but shrink sellable stock during peaks.
- Short windows recover stock quickly but can cancel a slow but real buyer.
- Reservations must be idempotent so a retried request does not double hold.
Treat the reservation, not the order, as the unit that controls scarcity. The order is the receipt that a reservation was kept.
Key idea
A reservation is a short lived lease on a unit of stock; sellable equals on hand minus active reservations, and expiry returns stock to the pool.