Design a flash sale system: the system design interview walkthrough
The request to design a flash sale system looks, at first, like an ordinary checkout — take an order, decrement the stock, charge the card. For a steady trickle of shoppers that is exactly what it is. But the interview asks you to sell a small, fixed inventory — a thousand units — to a crowd of millions who all press "buy" in the same second, never sell the 1,001st unit, keep it fair, and stay up while the traffic spikes three orders of magnitude above baseline. That is a contention problem, not a checkout. This is one of the sharpest flash sale system design prompts because the one-line brief hides a race condition on a single counter that a naive design loses instantly.
The round turns on two decisions. First, how you protect the one number everyone is fighting over — the item's stock count — so that a million concurrent writes never oversell it. Second, how you stop that million-strong wave from ever reaching your database at all, because the write path that survives a flash sale is the one that rejects 99% of traffic fast and cheap. The same spine drives a design a seckill system question and any high concurrency inventory system design: a tiny amount of stock, an enormous amount of demand, and a few seconds to resolve it. This walkthrough follows the path a strong candidate draws on the whiteboard — requirements, estimate, API and data model, high-level design, then the deep dives — and at each step it names the follow-up the interviewer uses to tell a memorised answer from an engineer who understands the tradeoff.
How the flash sale round is actually run
A flash sale round runs about 60 minutes on a shared canvas — you draw the boxes and arrows while you talk, and the interviewer interrupts. It is a favourite for the Amazon E-commerce Order Management loop because the one-line problem opens onto deep water fast: the moment you write "decrement the stock," the question becomes who decrements it, in what order, and what happens when a million requests do it at once — and every answer after that (overselling, spike absorption, reservations) compounds. Get the hot key and the load shedding clean and you have shown the whole system in one problem.
The interviewer rarely lets "take the order and decrement the stock" stand. "A million people hit 'buy' for 1,000 units in the same second — how do you not sell 1,001?" That question — a race condition on one counter under a design that is otherwise just a checkout — is the one a copied answer can never rehearse, and the one this round is really testing.
The rounds here are modelled on how the loop runs, not scraped from any candidate's recall. What matters for prep is the shape: a blank canvas, a clock, and a follow-up after every decision you make.
The five-step framework for any HLD round
Every high-level design answer fits the same spine. Say it out loud at the start so the interviewer knows you have a plan, then walk it:
- Clarify requirements — functional and non-functional, and what you are explicitly not building.
- Estimate — peak QPS, inventory size and rejection rate, to justify every later choice.
- High-level design — the boxes and arrows: client, waiting room, gateway, stock service, queue, fulfillment.
- Deep dive — the two or three decisions that actually decide this system.
- Follow-ups — bottlenecks, failure modes, and what you would change at ten times the scale.
What the debrief measures
The score is not "right or wrong design." A good HLD debrief reads on four dimensions, and every move below maps to one: problem solving (did you make overselling impossible with an atomic operation rather than a lock-and-pray), communication (did you say why the write path is deliberately thin in a sentence), technical execution (decrement in Redis, shed load at the edge, decouple accept-order from process-order with a queue, release reservations on a TTL), and time management (did you spend your 60 minutes on the hot key and the spike, not on the payment gateway). Reading a walkthrough teaches the design; it does not teach you to deliver it on the clock while someone pushes back.
Step 1 — Requirements: what a flash sale system must do
Spend the first few minutes here. Jumping to boxes before you have scoped the problem is the fastest way to design the wrong system.
| Type | Requirement |
|---|---|
| Functional | Sell a fixed inventory (e.g. 1,000 units) during a short window; accept an order only while stock remains; never confirm more orders than units; show "sold out" the instant the last unit goes; take payment and fulfil the confirmed orders. |
| Functional (optional) | One unit per user (anti-bot, anti-hoarding); a published start time; a queue position shown to waiting users — call these out, then scope most of them for later. |
| Non-functional | Survive an extreme read + write spike at sale start (orders of magnitude above baseline); strong consistency on the stock counter (never oversell); fairness (early or lucky, by a stated rule, not random corruption); graceful degradation (shed load, stay up, fail requests cleanly rather than fall over). |
The sentence that earns points: "Checkout is the easy part — the system is really a contention controller that lets exactly 1,000 writes through one hot counter and rejects everyone else fast enough that the database never feels the wave." Say that and you have framed the entire design before drawing a box.
Step 2 — Capacity estimation (back of the envelope)
Estimation here is about proving one thing: the hard axis is surviving the write spike on one hot key, not steady-state throughput.
| Quantity | Assumption | Result |
|---|---|---|
| Inventory | 1,000 units | the entire sale resolves in seconds — supply is tiny |
| Peak demand | ~1,000,000 users at t=0
|
a spike 3–4 orders of magnitude above baseline, in one second |
| Rejection rate | 999,000 of 1,000,000 fail | 99%+ of traffic must be rejected fast and cheap |
| The hot key | one stock counter | a single row/key every request contends on — the bottleneck of the whole system |
Two conclusions fall out, and you should say both out loud. First, the single stock counter is the system — a million requests all want to write the same number in the same instant, so that one key must live somewhere that can serialise writes in memory (Redis / an in-memory service), never a row lock on a disk-backed table hit a million times. Second, almost all of the traffic is doomed — only 1,000 can win — so the design's real job is to reject the 99% as early and as cheaply as possible, at the edge, before it costs you a database connection. You have now pointed the interview at the real deep dive before anyone asked.
Step 3 — API and data model
The public surface is tiny — two calls — because the whole design is about what happens behind them under load.
| API call | Operation |
|---|---|
POST /reserve → {reservation_id, ttl}
|
atomically decrement the stock counter; on success hand back a short-lived hold, on failure return "sold out" immediately |
POST /confirm → {order_id}
|
turn a valid, unexpired reservation into a paid order; idempotent on reservation_id
|
GET /status → `{available \ |
sold_out}` |
The data model is thin — most of the action is one number and a short list of holds:
| Entity | Notes |
|---|---|
inventory |
item_id, stock_remaining — the single hot key, held in Redis / an in-memory store for atomic decrement, not a disk row everyone locks. |
reservation |
reservation_id, user_id, item_id, expires_at — a short TTL hold that keeps a unit off the shelf while the user pays. |
order |
order_id, reservation_id (idempotency key), user_id, status, created_at — written after payment, off the hot path. |
user_purchase |
user_id → item_id, to enforce one-per-user and reject repeat attempts cheaply. |
Step 4 — High-level design: the write path
Now the boxes. The whole system is one deliberately thin write path that lets a tiny number of requests reach the stock counter and turns everyone else away early. Around that sit the pieces that absorb the spike and do the slow work off to the side:
- Client → CDN / static + waiting room: the sale page, "sold out" state and queue UI are served statically from the edge; a waiting room / virtual queue admits users to the buy endpoint in controlled batches rather than letting a million hit it at once.
- API gateway (rate limit + load shed): the first real line of defence — per-user and global rate limits, and load shedding that returns a fast "try again / sold out" instead of queuing work the system cannot do.
- Stock-reservation service (atomic decrement): the crux — a single atomic decrement on the hot stock key in Redis / an in-memory store; it returns a reservation on success and "sold out" the instant the counter hits zero.
- Message queue → async order processing: a successful reservation is enqueued; payment, order creation and fulfilment happen asynchronously, so accepting an order is decoupled from processing it.
- Payment + fulfillment: confirm payment against the reservation, write the durable order record, and release the reservation back to stock if the user never pays.
Say explicitly that this is a funnel, not a checkout — each layer exists to shrink the wave before it reaches the one counter that can only be written serially, and the counter's result (reserved vs sold out) is what everything downstream keys off. Naming the funnel unprompted is a signal the interviewer is listening for.
Deep dive: preventing overselling on a hot key
This is the first decision that actually decides the round. Every request wants to do the same three steps — read the stock, check it is greater than zero, write it back one lower — and the instant two requests read the same value before either writes, they both think they won, and you have oversold. A naive read-modify-write oversells under concurrency by construction; the whole deep dive is how you make "check and decrement" a single indivisible step.
| Approach | How it works | Why it does (or doesn't) hold |
|---|---|---|
| Naive read-modify-write | app reads stock, checks > 0, writes stock - 1
|
Oversells. Two requests read 1, both pass the check, both write 0 — two orders, one unit. Never propose this. |
| DB row lock (pessimistic) |
SELECT ... FOR UPDATE then decrement in a transaction |
Correct, but every request serialises on one locked row — the lock becomes the bottleneck and melts under a million QPS. |
| Optimistic (compare-and-set) | UPDATE ... SET stock = stock - 1 WHERE stock > 0 |
Correct and lock-free; the database rejects the losers atomically. Better, but a disk-backed row still can't take the full spike. |
| Atomic decrement in Redis (DECR / Lua) | one in-memory atomic op: decrement, and if it drops below zero, reject and add back | The senior answer. A single-threaded atomic operation serialises the contention in memory — no lost updates, no lock convoy, millions of ops/sec. |
The flow: a request hits the stock-reservation service, which runs an atomic decrement on the hot key — DECR guarded so it never goes negative, or a small Lua script that checks-and-decrements in one indivisible step. If the result is >= 0, the caller gets a reservation with a TTL; if it would go negative, you immediately return "sold out" and the counter is clamped at zero. Overselling is now impossible by construction, not prevented by hoping two transactions don't interleave — and the durable order is written later, off this path, so the hot key does the one thing it must do and nothing else.
"A million people hit 'buy' for 1,000 units in the same second — how do you not sell 1,001?" One atomic decrement on a single in-memory counter serialises every attempt; the 1,001st decrement returns a value below zero, you reject it and clamp at zero. Say the words atomic and single key — a row lock is correct but won't survive the spike, and a read-then-write is just wrong.
System Design
HLD · Payments & marketplaces · 60 min
Design a flash sale system out loud, with follow-ups
Deep dive: absorbing the spike
This is the decision most candidates under-think. Protecting the counter is necessary but not sufficient — if a million requests all reach the counter, even an in-memory decrement is drowning in connections, and your first line of defence has to sit far upstream of the database.
Shed load at the edge. The gateway enforces per-user and global rate limits and does load shedding — above a threshold it returns a fast, cheap "try again / sold out" rather than queuing work it cannot complete. A rejected request should cost you almost nothing; the cardinal sin is letting doomed traffic consume a database connection or a worker thread.
A waiting room / virtual queue. Instead of opening the floodgates at t=0, a waiting room issues each user a token and admits them to the buy endpoint in controlled batches at a rate the stock service can absorb. Users see a position and an estimated wait; the backend only ever faces a trickle it has sized for. This also makes fairness tractable — admission order is something you control, not a thundering-herd lottery.
Cache the "sold out" state. The moment the counter hits zero, flip a flag that the CDN and gateway read, so the vast majority of latecomers get a pre-generated "sold out" response from the edge and never touch the stock service at all. One boolean at the edge absorbs most of the tail.
Decouple accept from process. A successful reservation is dropped on a message queue; payment, order creation and fulfilment run asynchronously behind it. Accepting an order is a fast in-memory decrement plus an enqueue; the slow, failure-prone work (payment gateways, inventory systems) happens at the queue's pace, so a payment slowdown can never back-pressure the hot path.
"The database can't take the write spike — where does the first line of defence sit?" Not at the database — at the edge. Rate limiting and load shedding in the gateway, a waiting room that admits users in batches, and a cached "sold out" flag reject the 99% before they cost anything; only a sized trickle reaches the atomic counter, and the durable writes sit behind a queue.
System Design
HLD · Payments & marketplaces · 60 min
Defend a spike-proof write path out loud
Deep dive: fairness, consistency and releasing reservations
Holding stock turns the problem from a single decrement into a small state machine, and the moment it does, three things need care — because a reserved unit that is never paid for is a unit you can neither sell nor count as sold.
The core move is a reservation with a TTL: a winning decrement does not create an order, it creates a short-lived hold (say 2–10 minutes) that keeps the unit off the shelf while the user checks out. That hold forces you to answer the hard questions — what if they never pay, what if they retry, and does the counter still add up at the end.
| Concern | Naive | Correct |
|---|---|---|
| Abandoned carts | reserved stock is gone forever | a reservation has an expires_at; a sweeper (or a TTL key) releases it back to stock on expiry, so abandoned holds return to the sale. |
| Retries / double-buy | a retried confirm charges twice |
confirm is idempotent on reservation_id — a repeated request returns the same order, never a second one. |
| Fairness | random under contention | admission order from the waiting room plus one-per-user checks make "who wins" a stated rule, not corruption. |
| Drift | counter and orders disagree | a reconciliation job compares stock_remaining + active reservations + confirmed orders against the original inventory and repairs drift. |
Say the release path out loud: when a reservation expires, the unit is incremented back onto the hot key and becomes buyable again — which is why the decrement and the release must both be atomic, or you reintroduce the very overselling you designed out. Idempotency on the confirm step is the other half: under a flaky network the client will retry, and the reservation_id is what guarantees one hold becomes exactly one order.
"A user reserves an item then never pays — how does that stock come back?" The reservation carries a TTL; when it expires, a sweeper or TTL callback atomically increments the unit back onto the stock counter and frees the hold, so the unit re-enters the sale. Confirm is idempotent on the reservation id so a late payment or a retry can't double-count it, and a reconciliation pass catches any drift.
The follow-ups that decide the flash sale round
Scan the probes from each deep dive and they rhyme. Master these five and you are ready for a version of the question that is not drawn exactly like this one.
- "A million buys for 1,000 units — how do you not sell 1,001?" → One atomic decrement on a single in-memory stock key; the over-count attempt returns below zero and is rejected. (problem solving)
- "The database can't take the write spike — where's the first line of defence?" → At the edge: rate limiting, load shedding, a waiting room, and a cached "sold out" flag reject the 99% before they cost anything. (technical execution)
- "A user reserves then never pays — how does the stock come back?" → A TTL on the reservation; on expiry the unit is atomically returned to the counter, and confirm is idempotent so retries can't double-buy. (problem solving)
- "Why not just lock the row and decrement it?" → A pessimistic row lock is correct but serialises a million requests on one locked row and melts; an in-memory atomic op or a compare-and-set survives the spike. (communication)
- "What's the real bottleneck at sale start?" → Not bandwidth or payment — contention on the single hot stock key, which is why the write path is thin and everything slow sits behind a queue. (technical execution)
Each maps to a debrief dimension. Reading this list teaches you the answers; it does not teach you to deliver them while someone interrupts — that only comes from saying them out loud.
How to prepare: a one-week plan
You do not need fifty systems. You need this one cold and the framework automatic, so the next "design X" is just new nouns in the same five steps.
- Days 1–2: Learn the five-step framework until it is reflex. Do the flash sale end to end on paper — requirements, estimate, data model, the client → waiting room → gateway → stock service → queue → fulfillment funnel.
- Days 3–4: Drill the overselling deep dive: why read-modify-write loses, why a row lock won't scale, and why one atomic decrement on a single key is the answer. Say each tradeoff in one sentence.
- Days 5–6: Own spike absorption and reservations — load shedding, the waiting room, the cached sold-out flag, the message queue, and the reservation TTL / idempotency / reconciliation triangle. Answer each of the five follow-ups out loud.
- Day 7: A full timed 60-minute round, narrating the whole way, with someone (or something) interrupting. This is the rep that counts.
This post is the deep walkthrough behind one row of the broader Top 25 system design interview questions — once the flash sale is automatic, the same spine carries the rest of the list.
Frequently asked questions
How do I design a flash sale system step by step?
Follow the five-step HLD framework. Clarify requirements (sell a small fixed inventory to a huge concurrent crowd, never oversell, stay fair, degrade gracefully); estimate to show the hard axis is the write spike on one hot stock key and that 99% of traffic must be rejected cheaply; define the two-call API (reserve, confirm) plus the inventory, reservation and order model; draw the thin write path (client → waiting room → gateway → stock-reservation service → queue → payment and fulfillment); then deep-dive the decisions that matter — preventing overselling, absorbing the spike, and releasing reservations. Finish on the follow-ups about abandoned carts and the real bottleneck.
How do you prevent overselling in a flash sale system?
You make "check stock and decrement it" a single indivisible operation so two requests can never both think they won. A read-modify-write in application code oversells under concurrency; a pessimistic row lock is correct but serialises every request on one locked row and collapses under the spike. The senior answer is an atomic decrement on one in-memory stock key — a Redis DECR guarded against going negative, or a small Lua script that checks and decrements in one step — which serialises a million attempts in memory, rejects everything past the 1,000th, and makes overselling impossible by construction.
What is a seckill system and how is it different?
"Seckill" (a direct translation of the Chinese term for a seconds-long flash sale) is the same problem under a different name: a very small inventory, an enormous instantaneous crowd, and a few seconds to resolve it. The design concerns are identical — an atomic decrement on a hot key to stop overselling, load shedding and a waiting room to absorb the spike, and a message queue so accepting an order is decoupled from the slow payment and fulfillment work. If you can design a flash sale system you can design a seckill system; the vocabulary changes, the contention problem does not.
How does a flash sale system handle the traffic spike?
The first line of defence sits at the edge, not the database. The API gateway rate-limits per user and globally and sheds load, returning a fast "try again / sold out" instead of queuing work it cannot do. A waiting room issues tokens and admits users in controlled batches, so the stock service only ever faces a trickle it was sized for; a cached "sold out" flag at the CDN serves a pre-generated response to latecomers so they never touch the backend. Behind the accepted requests, a message queue runs payment and fulfillment asynchronously so slow downstream systems never back-pressure the hot path.
What happens to reserved stock if a user never pays?
A winning decrement creates a short-lived reservation with a TTL, not an order, so the unit is held only while the user checks out. If the reservation expires unpaid, a sweeper or a TTL callback atomically increments the unit back onto the stock counter, and it re-enters the sale. The confirm step is idempotent on the reservation id, so a late payment or a network retry turns one hold into exactly one order and never double-counts, and a reconciliation job periodically checks that stock plus active reservations plus confirmed orders still equals the original inventory.
How do I practise a system design interview out loud?
Reading a walkthrough is not the same as defending a design while someone interrupts. On Zynter, the HLD track runs live voice rounds modelled on how real system design loops run — you talk through a shared design on the canvas, and a voice interviewer pushes with the follow-ups above one at a time, then gives you a debrief on problem solving, communication, technical execution, and time management. The score is a practice signal, not a hiring decision.
Practise it on Zynter
You can read every layer. The round is won on the hot key and the load-shed case.
Pick the E-commerce Order Management round, draw the flash sale funnel on the canvas, and defend it out loud to a voice interviewer that keeps asking "how do you not sell 1,001?" and "where does the first line of defence sit?" — then read the debrief. Zynter.ai is on-demand mock interviews modelled on real company loops, with 150+ rounds across 20 companies including the HLD system design track (Sep 2026).




Top comments (0)