Flash-sale survival kit
1M shoppers, 10k units: edge caching and token buckets tame the flood, sharded counters kill the hot key, and a leveled queue means the database never meets the crowd.
What this design does
A flash sale is a self-inflicted DDoS with revenue attached. The kit: cache the product page at the CDN so the crowd's reads never reach you; rate-limit buyers with token buckets so the flood becomes a stream; split the one impossible hot key — remaining stock — across 16 sharded counters; and turn purchases into queued jobs so the database consumes the sale at its own pace. Everything the customer sees stays fast; everything that matters stays correct.
The patterns it composes
- Token-bucket rate limiting — per-user budgets turn 1M clicks into a fair, bounded stream
- Hot-key mitigation + sharded counters — stock count splits across 16 shards — no single contended key
- Queue-based load leveling — buy attempts queue; the DB writes orders at ITS pace
- Cache warming — product data is pre-loaded before T-0 — no cold-start stampede
- Load shedding — past capacity, excess buyers get an instant honest answer, not a hang
Import it, attach your own numbers, and verify the design against failures — or read the engineering notes.