Design a flash sale / limited inventory drop
Ten thousand units of a product go on sale at 10am sharp. A million people will try to buy them in the first minute. Nobody may buy a unit that does not exist.
What they are actually testing
Correctness under extreme contention, and cost awareness. They will push on what happens when the cache is stale, and on whether you can justify the cost of the capacity you just asked for.
Show model answer
Split by what must be exact. Browsing, product pages and the stock indicator can all be stale and cached hard, and that covers most of the million requests. Only the claim of a unit must be exact. The design is about keeping that exact tier small.
The number that changes the design: only 10,000 writes will ever succeed. That is trivial. This is not a throughput problem, it is a contention problem. The work is rejecting the ~99% of attempts that must fail, cheaply, before they reach the database.
A waiting room in front. At 10am, admit users at a controlled rate rather than letting a million hit the checkout path. This converts an uncontrolled burst into a known rate the exact tier can serve, makes the experience honest (a position and an estimate, not an error), and doubles as the main anti-bot control.
The claim itself. One conditional update: decrement remaining where remaining is greater than zero, or insert a row for a specific unit with a unique constraint. If it affects one row you have it; if zero, you do not. Explicitly not a read-then-write in application code, because that gap is the race. And explicitly not a distributed lock: the database row is already a single point of serialisation, and a lock adds a failure mode where a paused holder's lease expires and two processes both believe they won.
Idempotency. Mobile clients retry often. Every purchase attempt carries a client-generated key, inserted with a unique constraint in the same transaction as the claim, so a retry replays the original result rather than buying twice.
Numbers, said out loud. A million people in the first minute is roughly 17,000 arrivals a second on average, and far more in the first few seconds, because people refresh at 09:59:59. Each person makes several requests (page, stock, buy), so plan for something like 50,000 to 100,000 requests a second at the peak. Against that, at most 10,000 claims can ever succeed, and the exact tier needs to handle only a few hundred claim attempts a second if admission control in front of it is doing its job.
Data model. One row per sale: sale(id, sku, starts_at, total, remaining). One row per successful claim: claim(sale_id, user_id, idempotency_key, status, expires_at), with a unique constraint on (sale_id, user_id) if the rule is one unit per person, and on idempotency_key. The claim and the decrement happen in one transaction, so the count and the claims can never disagree.
The API. POST /sales/{id}/claims with an Idempotency-Key header returns either a claim with a payment deadline or "sold out". The waiting room hands each admitted user a short-lived signed token, and the claim endpoint rejects requests without one, so nobody can skip the queue by calling the API directly.
A claim is a hold, not a sale. Winning the claim reserves a unit for a few minutes while the person pays. If payment does not complete before expires_at, a background job marks the claim expired and increments remaining in the same transaction, and the unit goes back to the next person in the waiting room. Without this, abandoned checkouts would quietly sell out the stock with nothing paid for.
If one row is too hot. A single remaining row serialises every claim, and at a few hundred claims a second that is fine on one database. If the rate were much higher, split the inventory into, say, 20 buckets of 500 units each, route each claim to a random bucket with stock, and treat the sale as sold out when every bucket is empty. The cost is that the last few units can be briefly reported as gone while one bucket still has some, which is acceptable for a sale page.
Fairness and bots. The waiting room is where fairness lives: a randomised position for everyone who arrived before 10:00, then first come first served, per-account and per-payment-method limits, and the signed token so scripts cannot bypass it. Be honest that bot defence is an arms race; the design makes cheating expensive rather than impossible.
What to watch during the minute. Admission rate, claim success and failure counts, remaining against the claim table, and payment completions against expired holds. If remaining plus active claims ever differs from the total, stop the sale: that alert is the oversell check.
Pre-scale, because the time is known. This spike is scheduled, so pre-warm caches and scale out beforehand rather than relying on autoscaling that reacts over minutes to a spike that arrives in seconds.
The cost answer. The expensive capacity is needed for one minute. So the waiting room and the static tier, both cheap, absorb the load, and only a small exact tier is scaled up, briefly. Serving the product page from a CDN means the million requests mostly never reach compute I pay for by the second.
All 5 hints
- Hint 1 — Split the problem first: A million people arrive but only ten thousand can succeed. Are all of those requests doing the same kind of work? Which parts have to be exact, and which can be slightly wrong?
- Hint 2 — Count the successful writes: How many writes will ever succeed here, in total, across the whole sale? Compare that to the request rate. Does that change what the hard problem is?
- Hint 3 — Think about the traffic shape: This is not steady load. It is a wall arriving at a known second. What can you do with the fact that you know when it starts?
- Hint 4 — The dangerous bit: If you cache "units remaining" and two people read the same stale number, what happens? Which number is safe to cache and which is not?
- Hint 5 — Now the cost question: You have asked for capacity to absorb a million concurrent users. What does that cost for the 23 hours a day when nothing is happening?
The follow-up they will ask next
"Your stock counter is cached and shows 50 left when there are actually 0. What happens?"
What a strong answer covers (the rubric)
- Separated the cacheable stale tier from the small exact tier
- Noticed total successful writes are bounded by inventory, so it is contention not throughput
- Waiting room or admission control to convert the burst into a rate
- Claim is a single conditional update, not check-then-write
- Explicitly rejected a distributed lock and explained why
- Idempotency keys on purchase attempts
- Used the fact that the start time is known: pre-scaling and cache warming
- Answered the cost question: cheap tiers absorb the spike, expensive tier stays small
- Put numbers on the burst and on the exact tier
- Claim is a time-limited hold, released when payment does not complete
- Had an answer for a hot inventory row: split it into buckets
- Signed waiting-room token so the queue cannot be skipped
This question is written in the style of Amazon’s interview round. This site is not affiliated with or endorsed by Amazon.