Payments / Intermediate / 5 min
Flash sale: inventory holds
Ten phones, hundreds of buyers. Check-then-write oversells; holds on Buy reserve a unit and release it if the buyer abandons.
Start the simulation → Change the load, break a part, watch what happens. Free, no sign-up.
In short
- What it is
- Inventory reservation gives a buyer a time-limited hold on a unit when they click Buy, and turns it into a sale when they pay.
- Why it matters
- In a flash sale thousands of buyers race for a few units, and a naive read-then-write sells stock you do not have.
- The trade-off
- Long holds lock stock behind buyers who never pay; short holds rush real buyers; the hold store must be atomic and fast (often Redis).
- Say it in an interview
- "Reserve with an atomic DECR (or UPDATE … WHERE stock > 0) plus a hold row with a TTL; payment confirms it, expiry returns the unit."
Check yourself
Why does "read stock, check it is above 0, then write stock − 1" oversell?
Answer: Many buyers read the same value at once, and each writes its own stock − 1. A read-then-write race: use a conditional update (WHERE stock > 0) or a lock so only one decrement wins per unit.
What does a hold on Buy add over an atomic update at checkout?
Answer: The buyer learns at once whether a unit is theirs, before typing their card. The unit is reserved up front with an expiry, so late buyers see "sold out" immediately.
What happens to a hold if the buyer abandons checkout?
Answer: The hold expires and the unit goes back on sale. Holds have a time limit (often 10 to 15 minutes), after which the reserved unit returns to stock.