Skip to content

Use case · E-commerce

Flash sale checkout

A limited drop opens and every buyer hits checkout in the same second. Watch one sale go through, lock up under a crowd, then hold with a queue and per-unit holds.

Used by apps like Shopify stores, Nike SNKRS, Supreme, Amazon Lightning Deals and Zalando

Happy path · break it · fix it

Flash sale checkout: sequence diagram

POST /buyBuyerappAPIedge + appInventorystock DBPaymentsOrders

Flash sale checkout, shown as messages between Buyer (The buyer's browser or app), API (The load balancers at the edge and the checkout application behind them), Inventory (The inventory service and the database rows that hold stock), Payments (The payment provider that authorises the card), Orders (The order service that records the finished purchase).

Happy path: 8 steps.

  1. Buyer → API: POST /buy. One buyer presses Buy, and the app sends a single checkout request.
  2. API → Inventory: reserve 1. Before any money moves, checkout sets one unit aside for this buyer for ten minutes.
  3. Inventory → API: unit held (reply). The unit is held, so nobody else can buy it while this buyer pays.
  4. API → Payments: charge card. Only now is the card charged, with the unit safely on hold.
  5. Payments → API: approved (reply). The payment provider approves the charge.
  6. API → Orders: create order. The order is written once, after the payment has succeeded.
  7. API → Inventory: claim unit. The hold becomes a sale: the unit leaves stock for good and the timer stops.
  8. API → Buyer: 200 paid (reply). The buyer sees a confirmation, about a second after pressing Buy.

Result: One buyer, one unit, one charge, one order.

Break it: 9 steps.

  1. Buyer → API: POST /buy (many at once). The drop opens and a crowd presses Buy in the same second.
  2. API → Inventory: reserve 1 (many at once). Every checkout goes straight through and asks for a unit of the same product.
  3. Inventory: 1 stock row, 3 writers. Stock is one row with a count, so every buyer must change that row and they line up on its lock.
  4. Inventory → API: unit held (reply). One buyer gets the lock and a unit; the others are still waiting behind it.
  5. Inventory → API: timeout (never arrives) (reply) (many at once). The waiting checkouts run out of time before the lock is free, so no answer comes back.
  6. API → Buyer: 504 (reply) (many at once). Those buyers see an error page, with stock still on the shelf.
  7. Buyer → API: retry (many at once). They refresh at once, and newcomers keep arriving, so the request count goes up.
  8. API → Inventory: reserve 1 (many at once). Each retry is another writer on the same locked row, so the line gets longer.
  9. API → Orders: create order (never arrives). Orders share the stalled database, so even the buyer who holds a unit cannot finish.

Result: Checkout is stuck behind one row and nobody can finish buying.

Fix it: 10 steps.

  1. Buyer → API: POST /buy (many at once). The same drop, the same crowd, the same second.
  2. API: fair queue: 2 go in. The edge lets buyers in at a steady rate, first come first served; the third buyer waits in line.
  3. API → Inventory: reserve 1 (many at once). Stock is one row per unit: each buyer locks a different free row and skips rows already taken.
  4. Inventory → API: units 7, 8 (reply) (many at once). Both get a unit at once, since neither had to wait for the other's lock.
  5. API → Payments: charge card. The first buyer pays for unit 7.
  6. Payments → API: approved (reply). The charge is approved while the hold is still running.
  7. API → Inventory: claim 7. Unit 7 is sold, and its hold ends as intended.
  8. Inventory: unit 8 back in stock. The second buyer walked away, so that hold runs out and unit 8 returns to stock by itself.
  9. API → Inventory: reserve 1. The third buyer's turn comes, and the freed unit 8 is there to reserve.
  10. API → Buyer: 200 paid (reply) (many at once). Two units, two buyers, and the database never had more work than it could do.

Result: Nobody waits on a lock, nothing is oversold, abandoned units come back.

step 1 of 8

One buyer presses Buy, and the app sends a single checkout request.

  • request
  • success
  • held / reserved

At scale

One buyer never shows this failure. Turn up the crowd and compare: with no queue the database tips over; with a line at the edge it keeps selling. All numbers are illustrative.

Numbers are illustrative: a small simulation, not a measurement.

The happy path, step by step

  1. The buyer presses Buy and the app sends one checkout request.
  2. Checkout asks inventory to reserve one unit before any money moves.
  3. Inventory sets the unit aside with a hold that expires, for example after ten minutes.
  4. Checkout asks the payment provider to charge the card.
  5. The payment provider approves the charge.
  6. Checkout writes the order once, after the payment has succeeded.
  7. Checkout claims the held unit, which removes it from stock for good and ends the hold.
  8. The buyer sees a confirmation.

The failure

What breaks and why

When a drop opens, every buyer wants the same few units in the same second. If stock is one row with a count, every checkout has to read and change that one row, so writers queue on its lock, and a check made a moment ago is already out of date: two buyers can both see “1 left”. Lock waits turn into timeouts, buyers refresh and send the same writes again, and the database that also holds carts and orders slows down for everything that shares it. To shoppers the site has crashed, and what does get through may be oversold.

Before / after

The fix

Three changes, each aimed at one part of the jam. At the edge, admit buyers to checkout at a rate the database can sustain and keep the rest in a first-come line with a waiting page. In inventory, keep one row per sellable unit and claim a free one with SELECT … FOR UPDATE SKIP LOCKED: buyers lock different rows, never wait on each other, and no unit can be claimed twice. Give every claim an expiry, so an abandoned checkout hands its unit back after a few minutes.

Before · SQLRead, check in the app, write
-- one row per product, shared by every buyer
SELECT qty FROM stock WHERE sku = 'TEE-01';
-- app: if qty > 0, carry on  (already stale)
UPDATE stock
   SET qty = qty - 1
 WHERE sku = 'TEE-01';
-- every checkout queues on this one row lock
After · SQLOne row per unit, with a hold
-- a hold is a unit row with an expiry
START TRANSACTION;
SELECT id FROM stock_units
 WHERE sku = 'TEE-01'
   AND (held_until IS NULL OR held_until < NOW())
 LIMIT 1
   FOR UPDATE SKIP LOCKED;  -- taken rows are skipped
UPDATE stock_units
   SET held_by = :checkout,
       held_until = NOW() + INTERVAL '10' MINUTE
 WHERE id = :id;
COMMIT;

Boss fight

Diagnose the real outage

The real outage

A celebrity make-up sale sold out in minutes. It also took down every other shop on the same database. The next sale was a week away. What would you ship first?

Fight the boss

90 seconds · the company is revealed after you answer

From their own write-ups

How real companies approach it

How this comes up in interviews

"Design checkout for a limited drop where every buyer arrives in the same second and stock must never be oversold."

Then they ask

  1. Stock is one row with a count. What happens to the database when the crowd arrives?
  2. A buyer abandons checkout after a unit was held for them. How does that unit get back on sale?
  3. Why show buyers over the limit a queue page at the edge, and not an error?

A strong answer covers

  • Reserve a unit with a hold that expires before any money moves, and claim it after the payment has succeeded.
  • One row with a count makes every checkout wait on one lock, and a check made a moment ago is already out of date.
  • Keep one row per sellable unit and claim a free one with SKIP LOCKED: buyers lock different rows and no unit is claimed twice.
  • At the edge, admit buyers at a rate the database can sustain and keep the rest in a first-come line.
  • Every claim has an expiry, so an abandoned checkout hands its unit back.

Points to cover, not a script. Say them in your own words and tie them to a system you have worked on.

Your turn

What would you do?

A sneaker drop opens at 10:00. Within a minute checkout takes 30 seconds, the stock database shows hundreds of transactions waiting on one row, and other shops on that database slow down. Which change removes the cause?

Flash sale checkout questions

What is a reservation hold in checkout?
A short claim on one unit of stock, taken before payment starts. It stops anyone else buying that unit while the buyer pays. A successful payment turns the hold into a sale; if the buyer leaves, the hold expires and the unit goes back on sale.
Why use SELECT … FOR UPDATE SKIP LOCKED for inventory?
It locks rows that are free and passes over rows another transaction has locked, instead of waiting for them. With one row per unit, many buyers can each claim a different unit at the same moment, and the database guarantees no row is handed out twice.
Why show a queue page instead of returning 429 during a flash sale?
Both limit how many buyers reach checkout. A 429 looks like a broken site to a shopper, who then refreshes and adds load. A queue page says the sale is working, keeps the buyer's place in arrival order, and lets them in when there is room.

Sources: Shopify Engineering: Surviving flashes of high-write traffic using scriptable load balancers, part I ↗ · Shopify Engineering: Surviving flashes of high-write traffic using scriptable load balancers, part II ↗ · Shopify Engineering: We replaced Redis with MySQL for inventory reservations, and it scaled (2026) ↗ · PostgreSQL documentation: SELECT, the locking clause (SKIP LOCKED) ↗ · Report a problem

Last updated: Engineering write-up

A typical design, informed by public write-ups, not any one company's exact system. Diagrams are our own. Numbers in the simulation are illustrative. All wording is original and paraphrases the linked sources.