Scenario: a flash sale oversells inventory Intermediate
Estimated reading time: 1 min read
Three incidents follow one another during a flash sale. At each step you choose a response, then see right away what happens.
- If you pick wrong, read the explanation and Try again.
- Scoring counts only your first choice at each step, so think before you click.
Flash sale: 10 items, 50 people click Buy
You are the backend dev who owns checkout. Each choice immediately shows its consequences on the metrics below.
Oversold orders40
5xx errors0 %
Checkout p99180 ms
Duplicate orders / double charges0
Step 1/3 · Overselling
The flash sale ends: stock had 10 items but the system created 50 orders. Not a single error in the logs. The code even runs inside a proper BEGIN ... COMMIT.
- final stock
- 9
- orders created
- 50
- isolation
- READ COMMITTED
BEGIN; SELECT stock FROM product WHERE id = $1; -- app sees stock = 10 -- app: if (stock >= 1) ... UPDATE product SET stock = $2 WHERE id = $1; -- $2 = stock - 1 computed in the app INSERT INTO orders ...; COMMIT;
What do you do?
After playing, read Writing transactions in code for a demo that measures all 5 approaches with 50 concurrent requests.