Design Flash Sale Inventory Gate
Handle a sudden burst of 50,000 checkout requests/sec (80% writes) without overselling inventory. Target p99 latency under 150ms and 99.9% availability.
| Category & Difficulty | E-Commerce & Fintech · MEDIUM |
|---|---|
| Traffic Profile | 50,000 RPS sustained, 100,000 RPS spike (20% reads / 80% writes) |
| Latency & Availability SLA | p99 < 150 ms · 99.9% availability |
| Monthly Infra Budget | $2,500/month |
| Commonly Asked At | Amazon, Alibaba, Flipkart, Shopify |
Scale, traffic & SLA targets
To pass in the DesignTheSystem simulator, your architecture must hold all four targets simultaneously across a 60-second load run (spiking up to 100,000 RPS):
- Stock (10,000 units): A limited drop: far more buyers than items, all in the first minute.
- Correctness (Zero oversold): Selling unit 10,001 is a refund, an apology and a news story.
Functional & non-functional requirements
Functional scope
- Shoppers can see whether the item is still in stock.
- Shoppers can try to buy one unit and learn quickly whether they got it.
- Stock decreases atomically: never below zero, never sold twice.
- Successful buyers get an order number and a confirmation.
Non-functional goals
- p99 latency under 150 ms at the spike.
- At least 99.9% of requests answered.
- Costs no more than $2,500 a month.
- Strict consistency for the stock count; order history can catch up a moment later.
- Survives a database or worker restart without losing accepted orders.
Core challenge: Count stock in one place, fast
Thousands of buyers race for the same few items. Check and decrease stock with one atomic step in memory, answer 'sold out' at once, and queue the real orders so the database fills them at a steady pace.
What breaks first?
Every purchase runs `UPDATE inventory SET stock = stock - 1 WHERE item_id = 42 AND stock > 0`. That is the same row for every buyer, and each update waits for the lock on that row. One row can take only a limited number of updates a second (hundreds to low thousands), and a bigger database does not help because the row lives in one place. Requests pile up behind the lock and time out.
Key architectural trade-offs
- Buyers see 'processing' for a moment instead of an instant final confirmation.
- More moving parts: Redis scripts, Kafka consumers and a reconciliation worker all need monitoring.
- The Redis count and the database can briefly disagree; the database is the record, Redis is the gate.
Starting architecture & how to practise
The simulator starts you with a baseline setup: Flash Buyers → Checkout Service → Inventory DB. Run the baseline under 50,000 RPS to watch exactly which component saturates first, then add caching, queues, replicas, sharding or CDN until latency, availability and cost all turn green.
Common interview questions for Flash Sale Inventory Gate
What are the target SLA and scale numbers for Flash Sale Inventory Gate?
Design for 50,000 RPS sustained (spiking to 100,000 RPS) with a 20% read / 80% write mix, keeping p99 latency under 150 ms, availability at or above 99.9%, and infrastructure spend within $2,500/month.
What is the main architectural bottleneck in Flash Sale Inventory Gate?
Thousands of buyers race for the same few items. Check and decrease stock with one atomic step in memory, answer 'sold out' at once, and queue the real orders so the database fills them at a steady pace.
How can I verify my Flash Sale Inventory Gate architecture works under load?
Open the live simulator to wire up load balancers, caches, queues, replicas, or shards and run a 60-second traffic simulation that grades latency, error rate, and monthly cost automatically.
Recommended lessons before you build
Shared state every server can see
Keep fast-changing state in one shared place instead of inside each server.
Ledgers and holds: never oversell
Record money as entries that add up, and reserve stock without overselling.
Queues: accept now, work later
Move slow work off the request and keep a queue from falling behind.
Related E-Commerce & Fintech problems
Design Digital Wallet & Payment Ledger
Design an ACID-compliant digital wallet and double-entry ledger handling 10,000 checkout transfers/sec. Ensure zero data loss, strict idempotency, and sub-100ms p99 latency.
Design Amazon
Design Amazon: Architect a scalable, highly-available distributed system capable of sustaining 25,000 peak RPS (80% reads). Maintain p99 latency under 80ms with 99.9% availability while optimizing monthly infrastructure cost within $600/mo.
Design Shopify
Design Shopify: Architect a scalable, highly-available distributed system capable of sustaining 25,000 peak RPS (80% reads). Maintain p99 latency under 80ms with 99.9% availability while optimizing monthly infrastructure cost within $600/mo.
Design Online Auction System
Design Online Auction System: Architect a scalable, highly-available distributed system capable of sustaining 80,000 peak RPS (20% reads). Maintain p99 latency under 100ms with 99.9% availability while optimizing monthly infrastructure cost within $2500/mo.