← Lessons

quiz vs the machine

Platinum1880

System Design

Flash Sale Architecture Deep Dive

Surviving a spike when everyone wants the same item at once.

7 min read · advanced · beat Platinum to climb

The spike

A flash sale sends a huge burst of traffic at one product at the same instant. The hot inventory row becomes a bottleneck and naive checkout collapses.

Defenses

  • Pre compute and cache the product page and price so reads do not touch the hot path.
  • Shard the counter so deductions spread across sub counters that sum to the total.
  • Token or coupon gating: issue a limited set of claim tokens equal to stock, then only token holders proceed.
  • Queue admission so requests are admitted at a rate the inventory system can absorb.

Degrade gracefully

  • Reject early with a clear out of stock signal rather than timing out.
  • Make every step idempotent because clients will hammer retry.
  • Keep payment off the hot path until a unit is actually claimed.

Key idea

Survive a flash sale by caching reads, sharding the hot counter, gating buyers with limited claim tokens, and admitting traffic at a rate inventory can absorb while failing fast when stock is gone.

Check yourself

Answer to earn rating on the learn ladder.

1. Why shard the inventory counter during a flash sale?

2. What does token gating achieve?

3. Why keep payment off the hot path until a unit is claimed?