Flash sales without overselling
Updated Nov 10, 2026 · 3 min read
A flash sale is a small amount of stock and a huge crowd arriving at the same second. Concert tickets, sneaker drops and game consoles all look like this. Two things go wrong. The site sells the same item twice, and the site falls over. They have different fixes, and you need both.
The race
The natural code reads the seat, checks it’s open, then marks it sold. Run it on two app servers at once and both reads can come back “open” before either write lands. Both fans get a confirmation for the same seat. Checking twice doesn’t help, and neither does a lock in each server’s memory, because each lock only sees its own server.
One conditional update
Close the gap by letting the database check and change the row in one statement.
UPDATE seats
SET holder = 7, held_until = now() + interval '10 minutes'
WHERE id = 12
AND (holder IS NULL OR held_until < now());The database locks the row while it runs the update, and the second update re-checks the condition after the first commits. One server gets “1 row changed” and the seat. The other gets 0 rows and tells its fan the seat is gone. No app code can get between the check and the change, because there’s nothing between them.
For general admission, where seats aren’t numbered, the same idea works on a counter, as in UPDATE events SET seats_left = seats_left - 2 WHERE id = 9 AND seats_left >= 2. Another option is SELECT … FOR UPDATE inside a transaction, which locks the row for the read and the write. It’s correct too, but it holds the lock longer, and under a flash sale that means more waiting.
Holds that expire
Fans need a few minutes to pay, so the first step is a hold, not a sale. Many fans close the tab instead of paying. If holds lasted until payment, those seats would be stuck, and the sale would say “sold out” with thousands unsold. So every hold carries an expiry time, and the update above treats an expired hold as open. Abandoned seats come back on their own, with no cleanup job.
When the fan pays, the final step marks the seat sold only if the hold is still theirs. A fan who took too long finds their hold gone, and their payment is never captured. Taking payment before the hold would be worse, because fans would pay for seats that are already gone.
Estimating the rush
A sale’s traffic isn’t spread over the day. It lands in the first minute, and every slow page makes fans refresh. Say 2 million fans arrive at 10:00 and each sends about 10 requests in that minute.
2,000,000 fans × 10 requests ÷ 60 s ≈ 333,000 requests/sA checkout backed by one database might take a few thousand purchases a second. Buying servers for a spike that’s 100 times bigger and over in minutes makes no sense, and the database couldn’t keep up anyway. The answer is to make the crowd wait.
The waiting room
A waiting room sits in front of checkout. It’s a simple page, cheap to serve from a CDN, that gives each fan a place in line based on when they arrived. As room opens up, it hands the next fans a signed pass, and checkout only accepts fans with a valid pass. Checkout’s load becomes a number you choose.
| Approach | What fans see | What checkout sees |
|---|---|---|
| Nothing in front | Errors and timeouts | Everything at once |
| Rate limiter with 429s | Random errors, so they refresh harder | Still a flood of retries |
| Autoscaling | Errors until new servers start | A spike that’s over before they’re ready |
| Waiting room | A fair line with a position | A steady rate you set |
Where the reads go
Inside checkout, most requests are fans looking at the seat map, and the rest are holds. A hold is a write and must go to the primary database. Seat maps change every second, so a cache can only keep them for a moment. Read replicas can take the rest of those views, even though they’re a second behind. A stale map might show a seat that just went, but the hold still runs on the primary, so it can never sell that seat twice. Moving reads off the primary leaves it free for the writes that matter.