DesignTheSystem/dev
MEDIUM E-Commerce & Fintech Asked at Amazon, Alibaba, Flipkart

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 & DifficultyE-Commerce & Fintech · MEDIUM
Traffic Profile50,000 RPS sustained, 100,000 RPS spike (20% reads / 80% writes)
Latency & Availability SLAp99 < 150 ms · 99.9% availability
Monthly Infra Budget$2,500/month
Commonly Asked AtAmazon, 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):

Peak traffic50,000 RPS20% reads / 80% writes
Latency (p99)< 150 ms99th percentile target
Availability99.9%Max error rate 0.10%
Monthly budget$2,500/moPriced per component
  • 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

Related E-Commerce & Fintech problems