Case Study 44 β Big Billion Days / Great Indian Festival (Flash Sale)
Design how Flipkart Big Billion Days (BBD) or Amazon Great Indian Festival (GIF) survive a national shopping spike: millions of users hit deal pages at the same second, carts explode, inventory vanishes in minutes, and payments must not double-charge.
This is not normal e-commerce from Case Study 16. A sale day is a planned DDoS you invite β 10β50Γ traffic, hot SKUs, and inventory correctness under extreme contention.
Related: Ticket Booking (flash holds), E-commerce Catalog, Rate Limiter, Caching, Payment / Wallet, Global DDoS Mitigation.
Practice first: After Β§2, name the three bottlenecks you expect: browse, inventory, or checkout/pay. Then read the estimates and see if you were right.
1. Problem β Why βscale the servers 2Γβ fails
On a normal Tuesday, Flipkart/Amazon look like:
Browse catalog β add to cart β checkout β pay β order confirmed
On BBD / GIF opening night:
- Everyone arrives at once β 8 PM IST, not a smooth curve
- 10 SKUs get 80% of clicks β iPhone, TV, detergent mega-packs
- Inventory is finite β 5,000 units, 500,000 people clicking βBuy Nowβ
- Bots and resellers hammer APIs
- Payments spike β UPI/card gateways have their own limits
- One bad deploy becomes national news
The system must:
- Keep deal pages and home feed up (even if degraded)
- Never oversell inventory (legal + trust)
- Not melt the primary database on hot SKU rows
- Checkout fairly β first successful payment wins, not random errors
- Recover when a dependency blips (PSP timeout, cache miss storm)
2. Requirements
Functional (sale-specific)
| Flow | Must work |
|---|---|
| Deal discovery | Home takeover, category deals, countdown, βComing Soonβ |
| Buy Now / Add to cart | For lightning deals; often Buy Now skips cart |
| Inventory | Show βX leftβ, sell out honestly, no ghost stock |
| Checkout | Address, payment, order confirmation |
| Waitlist / notify | Optional when sold out |
| Seller / marketplace | Many SKUs are FBA / Flipkart Assured β split fulfillment later |
Non-functional (the hard part)
| Property | Target |
|---|---|
| Home + deal page availability | 99.95%+ during sale window |
| Browse p99 | < 500 ms (degraded OK: stale counts) |
| Buy / reserve attempt | Fail fast if OOS (< 200 ms), donβt hang |
| Zero oversell on deal SKUs | Strong inventory invariant |
| Payment | Idempotent; no double charge on retry |
| Peak vs normal | 10β50Γ read; 100Γ+ on hero SKUs |
| Bot abuse | Rate limits, device attestation (awareness) |
Out of scope (MVP interview)
- Full ads auction for deal slots
- Dynamic pricing ML during the hour
- Cross-border tax
3. Back-of-the-envelope estimates
Numbers are India sale-night ballparks, not leaked Flipkart/Amazon capacity plans. Cheat sheet: 1 QPS β 86,400/day. Sale peaks are cliff-shaped, not 5Γ average β use 10β50Γ for the first 30β60 minutes.
Why we estimate
Sale night tells you which layer dies first:
- CDN + cache β browse
- Redis + atomic counters β inventory
- Queue + idempotency β checkout
- PSP β external ceiling
Assumptions (say out loud)
| Assumption | Normal day | Sale night (first hour) |
|---|---|---|
| Active users trying to shop | 2M/day spread | 20M in 60 min |
| Page views / user | 15 | 25 (refreshing deals) |
| βBuy Nowβ clicks / user | 0.3 | 2 (many failures) |
| Hero deal SKUs | β | 20 SKUs, 5k units each |
| Catalog SKUs total | 50M+ | same |
| Successful orders / hour at peak | ~50k/hour normal | 500kβ1M/hour class |
| Payment success rate | 95% | 85% (gateway stress) |
| Average order metadata | 3 KB | same |
Flipkart BBD and Amazon GIF differ in branding and seller mix; engineering shape is the same: spike + hot keys + inventory.
Step A β Traffic (QPS)
Browse / API reads (home, deal pages, product detail):
Sale hour page views = 20M users Γ 25 views = 500M views/hour
= 500M / 3,600 β 139,000 page views/s
API calls per page β 3β8 (home feed, deals, recommendations, images)
β 139k Γ 5 β 695,000 API reads/s (order of 700k/s)
Without CDN/cache this is impossible at origin.
With CDN on static + 90% cache hit on deal JSON:
Origin β 70k/s still brutal β pre-warm, edge cache, read replicas
Compare to normal:
2M DAU Γ 15 views = 30M/day β 350/s average
Sale peak β 700k/s β ~2,000Γ average browse API (cliff, not smooth 5Γ)
Buy Now / add-to-cart attempts:
20M users Γ 2 clicks = 40M attempts/hour β 11,000/s
Hero SKU subset:
5 hero phones Γ 11,000/s Γ 40% traffic share β 4,400/s on ONE sku_id
β classic hot-key problem
Successful checkout / order create:
Target 500k orders in peak hour β 140/s sustained success
With 85% pay success β ~165 order creates/s
Peak minute might be 3Γ β ~500 orders/s
This is SMALL compared to browse QPS β important insight!
Sale night is NOT 700k order writes/s; it's 700k reads/s + 11k inventory fights/s
Payment webhooks / captures:
~500 peak orders/s Γ 1.2 retries β 600 payment events/s
PSP scale β you queue and idempotize, don't sync-block UI
Step B β Storage & inventory math
Hero deal inventory:
20 SKUs Γ 5,000 units = 100,000 units total across heroes
Contention: 4,400 attempts/s on one SKU, 5,000 units
β sells out in ~1β2 seconds if every attempt succeeded
β most attempts MUST fail fast with "Sold Out"
Inventory row design:
Do NOT: SELECT stock FROM products WHERE id=? FOR UPDATE (4,400/s on one row)
DO: Redis DECR or Lua script on stock:{sku_id}
or sharded counter with async reconcile to DB
Orders storage:
500k orders/hour Γ 3 KB β 1.5 GB/hour metadata
Day of sale 5β10M orders β tens of GB β trivial for sharded OLTP
Cart (if used):
Flash "Buy Now" often bypasses long-lived cart
If 5M active carts Γ 1 KB β 5 GB Redis β fine
Step C β Bandwidth
Images / deal banners:
700k API/s Γ 200 KB image if uncached = 140 GB/s β CDN mandatory
Deal hero images pushed to CDN days before; immutable URLs
Static deal HTML fragments:
Edge cache "deal page shell" with client-side hydrate
Reduces origin HTML generation
Step D β Ratios & capacity table
| Path | Sale-night share | Plan |
|---|---|---|
| Browse / feed | ~95% of requests | CDN, cache, pre-warm, degrade recommendations |
| Inventory decrement | Hottest writes | Redis atomic, per-SKU isolation |
| Order create | Moderate | Sharded DB, async fulfillment msg |
| Payment | Spiky, external | Idempotency keys, webhook queue |
| Search | High but cacheable | Freeze index updates during peak minute optional |
| Metric | Order of magnitude |
|---|---|
| Peak API reads | 500kβ1M/s (with CDN: origin 50kβ100k/s) |
| Buy attempts | ~11k/s |
| Hot SKU writes | ~4k/s on one key |
| Successful orders | ~140β500/s |
| Oversell tolerance | 0 |
What the numbers tell us
- Optimize read path first β CDN + cache warming + deal page as mostly static
- Inventory is a specialized counter service, not generic SQL row locks
- Checkout QPS is modest; fairness and idempotency matter more than raw throughput
- Hero SKU is a micro flash sale inside the mega sale β same pattern as Ticket Booking
- Degrade gracefully: drop recommendations before drop buy button
- Load test at 2Γ expected weeks before; game day runbooks
Common mistake for this problem
βAdd 50 app servers.β Without CDN + inventory isolation + hot-key plan, servers only die slower. Another mistake: overselling because async inventory sync lagged behind Redis.
4. High-Level Design (HLD)
Sale-night control plane (how teams βoperateβ the sale)
| Lever | Purpose |
|---|---|
| Cache warm | Load hero deal JSON into Redis/CDN T-24h, T-1h |
| Feature flags | Turn off heavy reco, reviews, non-critical widgets |
| Traffic shedding | Queue page for βsoft wait roomβ if origin unhealthy |
| Read-only mode | Browse only if checkout catching fire (last resort) |
| Frozen deploys | Code freeze 72h before; only roll-forward fixes |
| War room | SLO dashboard: CDN hit %, Redis latency, oversell alarms |
Flipkart/Amazon run months of rehearsal β load tests, failure injection, runbooks β not just bigger VMs.
5. Timeline β what happens when the sale opens
T-7 days Deal SKUs ingested; inventory allocated; prices locked
T-48h CDN preload images; cache warm scripts
T-1h Scale out app + Redis clusters; disable non-critical jobs
T-0 Countdown ends β traffic cliff
T+0β5m Hero SKUs sell out; Redis DECR storm; "Sold Out" UX
T+5β60m Long tail browse + checkout for non-hero items
T+days Reconcile inventory ledger; refunds for edge cases
6. LLD β Inventory (the heart of the sale)
Two-phase inventory (like ticket holds)
Phase 1 RESERVE (on Buy Now click):
Lua: if stock[sku] >= qty then stock -= qty; create reservation_id TTL 600s
Phase 2 CONFIRM (on payment success):
mark reservation CONFIRMED; write order line; async persist to InvDB
Phase 3 RELEASE (TTL or payment fail):
stock += qty; reservation EXPIRED
Why TTL reservation? Stops hoarding: user clicks Buy but never pays β stock returns in 10 minutes.
Redis Lua sketch (conceptual):
-- keys: stock:{sku}, res:{reservation_id}
if GET stock:{sku} >= qty then
DECRBY stock:{sku} qty
SET res:{id} {sku, qty, user} EX 600
return OK
else
return SOLD_OUT
end
Reconcile to DB: async worker batches confirmed decrements to inventory_ledger for audit. Source of truth during sale minute is Redis; DB catches up.
Hero SKU sharding (advanced)
One Redis key stock:iphone16 still serializes 4k ops/s. Options:
- Pre-split buckets:
stock:sku:000..127random bucket decrement (sum = total) - Token bucket units: 5,000 tokens in list
LPOP(each token = one unit) - Accept serialization if 4k/s is within single Redis node limit (~100k ops/s) β often enough
Interview: mention single hot key and at least one mitigation.
7. LLD β Checkout & payments
POST /v1/deals/{sku}/buy
Headers: Idempotency-Key (device + user + sku + sale_window)
β reservation_id OR 409 sold out
POST /v1/checkout/sessions
Body: { reservation_id, address_id }
β session_id, payable_amount (frozen)
POST /v1/checkout/sessions/{id}/pay
β redirect to PSP / UPI intent
Webhook POST /v1/payments/webhook
β verify signature
β idempotent on psp_payment_id
β confirm reservation β create order β enqueue fulfillment
Idempotency: Same user double-taps Buy β same Idempotency-Key β same reservation or same error, never two decrements.
Payment pending: Show βProcessingβ; poll or webhook; never decrement twice on retry.
See Payment / Wallet for ledger patterns.
8. Read path β CDN, cache warming, degradation
| Asset | Strategy |
|---|---|
| Product images | CDN; immutable URL .../iphone16-bbd2026.jpg |
| Deal listing JSON | Redis deals:bbd:wave1 TTL 5s during peak; longer pre-open |
| Home feed | Precomputed modules; disable personalization first |
| Stock count on PDP | Eventual β show βFew leftβ bands; exact count from Redis with 1β2s cache |
| Search | Cache top queries; optional read-only index snapshot |
Cache stampede: Single-flight on hero keys β Caching.
Soft wait room (optional): If origin error rate > threshold, queue users with token before HTML (Ticketmaster pattern). Flipkart has used app-only deals to reduce web blast β product + capacity trade-off.
9. Bot abuse & fairness
- Rate limit per IP / user / device on
POST /buy(Rate Limiter) - Captcha on suspicious velocity
- Logged-in only for hero deals (reduces anonymous bots)
- One unit per user flag on hero SKU (
max_qty_per_user=1) stored in reservation service
Fairness > perfect UX for the first 60 seconds.
10. Flipkart BBD vs Amazon GIF (same engine, different skin)
| Dimension | Flipkart BBD | Amazon GIF |
|---|---|---|
| Traffic shape | National cliff, app-heavy | Same; Prime early access window |
| Inventory | Marketplace + Flipkart Assured | FBA + marketplace |
| Payments | UPI-heavy India | UPI + cards + COD (where enabled) |
| Early access | Plus / loyalty tiers | Prime early deals |
| Engineering | CDN + Redis inventory + sharded checkout | Same class of systems |
Interview answer: βSame flash-sale architecture; differences are business rules and seller mix, not magic databases.β
11. Schema sketches
sale_events(id, name, start_at, end_at, status)
deal_skus(sale_id, sku_id, deal_price_paise, stock_allocated, max_per_user)
-- audit / source after reconcile
inventory_ledger(sku_id, delta, reason, reservation_id, ts)
reservations(id, sku_id, user_id, qty, status, expires_at)
orders(id, user_id, sale_id, status, payable_paise, ...)
order_items(order_id, sku_id, qty, price_paise_snapshot)
payments(id, order_id, psp_ref, status, idempotency_key)
Redis (ephemeral during sale):
stock:{sku_id} β integer
res:{reservation_id} β hash, TTL
user_limit:{sale}:{user}:{sku} β 1 if max_per_user
12. Failure modes
| Failure | Symptom | Mitigation |
|---|---|---|
| Redis down | Cannot trust stock | Fail closed: disable Buy; browse only; restore from DB snapshot |
| Oversell bug | Orders > stock | Reconciliation job; cancel + refund; legal incident |
| PSP slow | Stuck on βPayingβ | Async webhook; reservation TTL releases stock |
| CDN miss storm | Origin overload | Pre-warm; raise TTL; shed widgets |
| Hot key Redis CPU | Latency on one SKU | Bucket split; local cache on app for read stock |
| DB primary hot | Checkout errors | Shard orders by user_id; queue order create |
| Bad deploy | National outage | Freeze; rollback; feature flags |
Golden rule: Never oversell. Better to show βTry againβ than sell 6,000 of 5,000 units.
13. Scale evolution
| Stage | Design |
|---|---|
| Normal ecommerce | Catalog + cart + SQL stock β Case 16 |
| First sale | Redis counters + CDN |
| National sale | Reservations + idempotent checkout + war room |
| Hero SKU wars | Bucketed inventory + rate limits |
| Multi-wave sale | wave2 cache keys; reset traffic between waves |
14. Interview talking points
- Sale night = read avalanche + write hot keys, not uniform scale-up.
- CDN + cache warm is as important as app servers.
- Two-phase inventory (reserve β confirm) like tickets.
- Checkout QPS is lower than browse β donβt optimize the wrong layer.
- Idempotency on buy and pay.
- Degrade features before dropping purchase path.
- Flipkart and Amazon share the same flash-sale playbook.
- Quote BOE: ~700k read/s cliff, ~11k buy attempts/s, ~4k/s on one SKU, ~500 order/s success.
15. Recap
Big Billion Days / Great Indian Festival engineering is planned overload:
- Push reads to CDN and Redis β origin sees survivable QPS
- Fight inventory with atomic counters + reservations, not row locks
- Checkout is orchestrated, idempotent, and queued
- Hero SKUs are mini ticket sales inside a national event
- Operate the sale β freeze, warm, flag, war room, reconcile
Practice: A hero phone has 5,000 units and 4,000 Buy clicks per second for 3 seconds. Walk through Redis DECR, reservation TTL, and payment webhook β how many orders confirm, and when does βSold Outβ appear?
Previous: Zomato / Food Delivery Β· Also: Ticket Booking, E-commerce