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:

  1. Everyone arrives at once β€” 8 PM IST, not a smooth curve
  2. 10 SKUs get 80% of clicks β€” iPhone, TV, detergent mega-packs
  3. Inventory is finite β€” 5,000 units, 500,000 people clicking β€œBuy Now”
  4. Bots and resellers hammer APIs
  5. Payments spike β€” UPI/card gateways have their own limits
  6. 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)

FlowMust work
Deal discoveryHome takeover, category deals, countdown, β€œComing Soon”
Buy Now / Add to cartFor lightning deals; often Buy Now skips cart
InventoryShow β€œX left”, sell out honestly, no ghost stock
CheckoutAddress, payment, order confirmation
Waitlist / notifyOptional when sold out
Seller / marketplaceMany SKUs are FBA / Flipkart Assured β€” split fulfillment later

Non-functional (the hard part)

PropertyTarget
Home + deal page availability99.95%+ during sale window
Browse p99< 500 ms (degraded OK: stale counts)
Buy / reserve attemptFail fast if OOS (< 200 ms), don’t hang
Zero oversell on deal SKUsStrong inventory invariant
PaymentIdempotent; no double charge on retry
Peak vs normal10–50Γ— read; 100Γ—+ on hero SKUs
Bot abuseRate 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)

AssumptionNormal daySale night (first hour)
Active users trying to shop2M/day spread20M in 60 min
Page views / user1525 (refreshing deals)
β€œBuy Now” clicks / user0.32 (many failures)
Hero deal SKUsβ€”20 SKUs, 5k units each
Catalog SKUs total50M+same
Successful orders / hour at peak~50k/hour normal500k–1M/hour class
Payment success rate95%85% (gateway stress)
Average order metadata3 KBsame

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

PathSale-night sharePlan
Browse / feed~95% of requestsCDN, cache, pre-warm, degrade recommendations
Inventory decrementHottest writesRedis atomic, per-SKU isolation
Order createModerateSharded DB, async fulfillment msg
PaymentSpiky, externalIdempotency keys, webhook queue
SearchHigh but cacheableFreeze index updates during peak minute optional
MetricOrder of magnitude
Peak API reads500k–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 tolerance0

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)

LeverPurpose
Cache warmLoad hero deal JSON into Redis/CDN T-24h, T-1h
Feature flagsTurn off heavy reco, reviews, non-critical widgets
Traffic sheddingQueue page for β€œsoft wait room” if origin unhealthy
Read-only modeBrowse only if checkout catching fire (last resort)
Frozen deploysCode freeze 72h before; only roll-forward fixes
War roomSLO 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..127 random 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

AssetStrategy
Product imagesCDN; immutable URL .../iphone16-bbd2026.jpg
Deal listing JSONRedis deals:bbd:wave1 TTL 5s during peak; longer pre-open
Home feedPrecomputed modules; disable personalization first
Stock count on PDPEventual β€” show β€œFew left” bands; exact count from Redis with 1–2s cache
SearchCache 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)

DimensionFlipkart BBDAmazon GIF
Traffic shapeNational cliff, app-heavySame; Prime early access window
InventoryMarketplace + Flipkart AssuredFBA + marketplace
PaymentsUPI-heavy IndiaUPI + cards + COD (where enabled)
Early accessPlus / loyalty tiersPrime early deals
EngineeringCDN + Redis inventory + sharded checkoutSame 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

FailureSymptomMitigation
Redis downCannot trust stockFail closed: disable Buy; browse only; restore from DB snapshot
Oversell bugOrders > stockReconciliation job; cancel + refund; legal incident
PSP slowStuck on β€œPaying”Async webhook; reservation TTL releases stock
CDN miss stormOrigin overloadPre-warm; raise TTL; shed widgets
Hot key Redis CPULatency on one SKUBucket split; local cache on app for read stock
DB primary hotCheckout errorsShard orders by user_id; queue order create
Bad deployNational outageFreeze; rollback; feature flags

Golden rule: Never oversell. Better to show β€œTry again” than sell 6,000 of 5,000 units.


13. Scale evolution

StageDesign
Normal ecommerceCatalog + cart + SQL stock β€” Case 16
First saleRedis counters + CDN
National saleReservations + idempotent checkout + war room
Hero SKU warsBucketed inventory + rate limits
Multi-wave salewave2 cache keys; reset traffic between waves

14. Interview talking points

  1. Sale night = read avalanche + write hot keys, not uniform scale-up.
  2. CDN + cache warm is as important as app servers.
  3. Two-phase inventory (reserve β†’ confirm) like tickets.
  4. Checkout QPS is lower than browse β€” don’t optimize the wrong layer.
  5. Idempotency on buy and pay.
  6. Degrade features before dropping purchase path.
  7. Flipkart and Amazon share the same flash-sale playbook.
  8. 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:

  1. Push reads to CDN and Redis β€” origin sees survivable QPS
  2. Fight inventory with atomic counters + reservations, not row locks
  3. Checkout is orchestrated, idempotent, and queued
  4. Hero SKUs are mini ticket sales inside a national event
  5. 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