Design a Flash Sale System with Zero Overselling

Quick Overview

Design a flash sale system where a limited stock goes on sale at a set moment and up to a million users try to buy it in the same second. It tests how you keep the stock count exact under heavy concurrency, absorb a sudden traffic spike, expire unpaid holds, and report order status to waiting users.

Design a Flash Sale System with Zero Overselling

Role: Software Engineer

Category: System Design

Difficulty: hard

Interview Round: Other

Design the backend for a flash sale. A limited stock of one product goes on sale at a fixed moment, and a very large number of users try to buy it in the same second. The system has to process that burst of concurrent purchase attempts while strictly guaranteeing that no unit is ever oversold. The system must support four things: 1. Viewing the flash sale product details and a countdown timer to the start of the sale. 2. Attempting a purchase the exact second the sale begins. 3. Viewing the status of an order (for example Queued, Payment Pending, Confirmed, Sold Out). 4. Returning the item to the pool when a user secures it but does not complete payment within a strict window (for example 5 minutes). State the non-functional requirements you are designing for, then walk through the data model, the API and a high-level design. Expect the interviewer to push on four areas: how you prevent overselling, how you survive the thundering herd when the sale opens, how inventory holds and payment fit together as a distributed transaction, and how the client learns the status of its order. ```hint Find the contended state Every buyer is competing for one number, the remaining stock. Think about what has to happen atomically on that number, and what a single hot key does to throughput. ``` ```hint Plan for the first second Autoscaling reacts in minutes and the spike arrives in one second. Separate the work that can happen before the sale starts from the work that can wait until after a reservation is accepted. ``` ```hint Follow an abandoned unit Trace one unit through a reservation that is never paid for, including a process crash between two steps. Decide who returns it to the pool and how that step stays safe if it runs twice. ``` ### Constraints & Assumptions - Around 1M users press Buy within the same second when the sale opens. - Stock is limited, on the order of 1,000 to 10,000 units. - Zero overselling: with 1,000 units, exactly 1,000 can be sold. - A user who secures a unit has 5 minutes to pay before it goes back to the pool. - Payment goes through an external payment gateway. ### Clarifying Questions to Ask - Is this one product with a single stock count, or several products in the same sale? - Is each user limited to one unit, and may a user whose hold expired try again? - Do users have to sign in or register before the sale starts, and how much bot traffic should the design expect? - Does the sale need strict first-come, first-served order, or is any fair outcome among the early requests acceptable? - What should happen to a payment that completes after the 5-minute window has closed? ### What a Strong Answer Covers - Non-functional requirements that put consistency of the stock count first, with concrete scale and latency targets. - An atomic check-and-decrement on inventory, and how it scales past a single hot key. - Protection against the spike at the start of the sale: pre-provisioning, CDN caching, layered rate limits, and a queue between reservation and order creation. - The reservation lifecycle: holds with a 5-minute deadline, payment confirmation, returning stock safely after abandonment or a crash, and idempotent retries throughout. - How the client learns its order status, and the read load that choice creates. ### Follow-up Questions - Inventory is split across shards by user ID, so one shard can sell out while others still have stock. How do you avoid telling users "sold out" too early? - A Redis primary fails over before its last few decrements reach the replica. Can you still guarantee zero overselling? - A payment webhook arrives a few seconds after the sweeper cancelled the order. What happens to the money and to the unit? - How would you add a virtual waiting room that admits users in a fair order?

Overview: Design a flash sale system where a limited stock goes on sale at a set moment and up to a million users try to buy it in the same second. It tests how you keep the stock count exact under heavy concurrency, absorb a sudden traffic spike, expire unpaid holds, and report order status to waiting users.

Nov 25, 2026
hardSoftware EngineerOtherSystem Design
0
0

Design the backend for a flash sale. A limited stock of one product goes on sale at a fixed moment, and a very large number of users try to buy it in the same second. The system has to process that burst of concurrent purchase attempts while strictly guaranteeing that no unit is ever oversold.

The system must support four things:

  1. Viewing the flash sale product details and a countdown timer to the start of the sale.
  2. Attempting a purchase the exact second the sale begins.
  3. Viewing the status of an order (for example Queued, Payment Pending, Confirmed, Sold Out).
  4. Returning the item to the pool when a user secures it but does not complete payment within a strict window (for example 5 minutes).

State the non-functional requirements you are designing for, then walk through the data model, the API and a high-level design. Expect the interviewer to push on four areas: how you prevent overselling, how you survive the thundering herd when the sale opens, how inventory holds and payment fit together as a distributed transaction, and how the client learns the status of its order.

Constraints & Assumptions

  • Around 1M users press Buy within the same second when the sale opens.
  • Stock is limited, on the order of 1,000 to 10,000 units.
  • Zero overselling: with 1,000 units, exactly 1,000 can be sold.
  • A user who secures a unit has 5 minutes to pay before it goes back to the pool.
  • Payment goes through an external payment gateway.

Clarifying Questions to Ask Guidance

  • Is this one product with a single stock count, or several products in the same sale?
  • Is each user limited to one unit, and may a user whose hold expired try again?
  • Do users have to sign in or register before the sale starts, and how much bot traffic should the design expect?
  • Does the sale need strict first-come, first-served order, or is any fair outcome among the early requests acceptable?
  • What should happen to a payment that completes after the 5-minute window has closed?

What a Strong Answer Covers Guidance

  • Non-functional requirements that put consistency of the stock count first, with concrete scale and latency targets.
  • An atomic check-and-decrement on inventory, and how it scales past a single hot key.
  • Protection against the spike at the start of the sale: pre-provisioning, CDN caching, layered rate limits, and a queue between reservation and order creation.
  • The reservation lifecycle: holds with a 5-minute deadline, payment confirmation, returning stock safely after abandonment or a crash, and idempotent retries throughout.
  • How the client learns its order status, and the read load that choice creates.

Follow-up Questions Guidance

  • Inventory is split across shards by user ID, so one shard can sell out while others still have stock. How do you avoid telling users "sold out" too early?
  • A Redis primary fails over before its last few decrements reach the replica. Can you still guarantee zero overselling?
  • A payment webhook arrives a few seconds after the sweeper cancelled the order. What happens to the money and to the unit?
  • How would you add a virtual waiting room that admits users in a fair order?