Design a Flash Sale Site
Understanding the Problem
🛒 What is a flash sale? A flash sale sells a small, fixed amount of stock at a big discount, starting at a set time and usually lasting minutes. Think of a sneaker drop, a $1 phone on Singles' Day, or a console restock. The defining feature is the shape of the traffic: almost nothing before the start time, then millions of people pressing "Buy" in the same second, for an item only a tiny fraction of them can get.
You will also hear this asked as "give away 6 million free burgers in 10 minutes, one per person." It is the same problem with a different coat of paint: a fixed pool of something, far more demand than supply, and a hard rule that you can't hand out more than you have.
Functional Requirements
We'll start by pinning down with our interviewer what users need to be able to do. Flash sales tie into a whole e-commerce stack (catalog, cart, shipping), so it's worth being explicit that we're only designing the sale itself.
Core Requirements
- Users should be able to view an upcoming or live sale: the product, the start time, and whether stock remains.
- Users should be able to attempt to buy an item once the sale starts, and get a clear answer: you got one, or it's sold out.
- Users who get an item should be able to pay for it within a short hold window (say 10 minutes). If they don't, the item goes back into the pool.
Below the line (out of scope)
- Creating and managing sales (an internal admin tool).
- Shipping, returns and refunds.
- Carts with multiple items. One sale, one product, one unit per user.
Non-Functional Requirements
This is where the problem lives. A flash sale is easy to build for a hundred users and very hard to build for ten million, so ask your interviewer for numbers. For our design: one sale sells 10,000 units, and 10 million users are waiting on the page when it opens.
Core Requirements
- The system must never sell more units than exist (no overselling). This needs strong consistency on inventory.
- The system should handle a spike of 10M users arriving within the first few seconds, roughly 1M requests per second at peak.
- Users should get a result (got it / sold out / still in line) within a second or two.
- The sale should be fair: roughly first come, first served, at most one unit per user, and resistant to bots.
- The rest of the site must keep working while the sale runs.
Below the line (out of scope)
- Multi-region active-active inventory. We'll run the sale out of one region.
- GDPR, PCI and other compliance work beyond "use a payment provider."
Do a quick bit of math here, because it changes the whole design. 10M users and 10,000 units means 999 out of every 1,000 purchase attempts are going to fail. Most of the engineering in this problem is about making those failures cheap. If every losing request takes a database lock, the database is busy doing nothing useful while the winners wait behind the losers.
A lot of candidates jump straight to "we need a really fast database." The sharper observation is that we don't need to do 1M writes per second at all. We need to do 10,000 writes and turn away the other 9,990,000 requests as early and cheaply as possible.