System design case study C13 · Spikes · Redis

Design an E-commerce Flash Sale

10,000 phones at a special price, 5 million people clicking "Buy" at 12:00:00. Sell exactly 10,000, fairly, and keep the rest of the store running.

What you'll be able to explain
  • Design catalog, cart and checkout for normal traffic
  • Reserve inventory atomically without oversell
  • Absorb a massive spike with admission control and queues
  • Keep the hot path tiny
  • Protect the rest of the platform during the sale

Scope

Functional

  • Normal store: catalog, search, cart, checkout, orders.
  • Flash sale: limited stock at a set time; max 1 unit per user; reserved units must be paid within 10 minutes or released.

Non-functional

  • Zero oversell. Fair (roughly first-come), bot-resistant.
  • The sale must not degrade the rest of the site.
  • Peak: 5M users, ~1M requests/s in the first seconds.

Size

  • 1M requests/s for a few seconds, then tailing off; only 10k can succeed.
  • The ratio is the insight: 99% of requests will fail. Make failure cheap and early.

The everyday store

CLIENTShoppersNETWORKCDNpages, imagesNETWORKGatewaySERVICECatalog + searchSERVICECartKV by userSERVICEOrders + checkoutDATABASEInventory DBEXTERNALPaymentsreserve
Normal e-commerce: read-heavy catalog, user-scoped carts, transactional orders.
  • Catalog: denormalised product documents, heavily cached, served via CDN for anonymous pages.
  • Cart: key-value by user_id (Redis/DynamoDB). Prices re-validated at checkout.
  • Inventory: reservation at checkout, decrement at payment, release on timeout (same pattern as seat holds in Case Study C11 of the book).

The flash-sale path

CLIENT5M usersNETWORKEdge / waiting roombot checks, tokenSERVICESale servicestatelessCACHERedisstock counter + buyers setQUEUE / LOGOrder queuewinners onlyWORKEROrder workersDATABASEOrders + inventory DBadmitted (rate-limited)atomic DECR + SADDreservation
Flash-sale funnel: cheap rejections at each layer; only winners reach the order system.

The 30-second summary

Say it in the interview

"The normal store is a cached catalog, KV carts and transactional checkout with inventory reservations. The flash sale gets its own funnel: an edge waiting room with bot checks admits users at a controlled rate; a stateless sale service runs an atomic Lua script that decrements stock and enforces one per user; winners are queued for durable order creation; and a sold-out flag at the edge rejects everyone else for free. It runs on isolated capacity so the store keeps working."

Follow-up questions the interviewer may ask

  1. How do you stop bots from buying everything?
  2. Why not just decrement stock in the database?
  3. What if Redis loses the counter?
  4. How do you make the sale fair across regions?

Model answers to each of these are in the book.