techdiagrams.net
← All templates

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.

Open in editor — free, no login Download JSON
THE ONLY WRITERS — SIZED FOR THE DB, NOT THE CROWDpage loadsbuy clicks onlyadmitted · 429 + retry-after past budgetstock readsbuy → queueddecrement shard hash(user)%16write orderpre-warm T-301M ShoppersT-0: everyone at onceEdge / CDNproduct page cachedRate Limitertoken bucket per userSale APIfast paths onlyStock Cachepre-warmed · shard-keyedCache WarmerT-30min: preloadBuy Attemptsleveled · at-least-onceOrder Workersconsume at DB paceStock Counters ×16sharded — no hot keyOrders DBnever meets the crowdthe survival ordering:cache absorbs reads → buckets meter intents →queue absorbs writes → shards absorb contention.the database never notices the sale

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

Import it, attach your own numbers, and verify the design against failures — or read the engineering notes.