SD-42 · Back to the write-up
Design a Flash Giveaway
Let the edge absorb the crowd, admit a steady 50,000 a second, count down 100 stock shards atomically, and issue coupons from a durable log.
Follow a request
Join the line
Claim a burger
Issue the coupon
Sold out
A lost answer
Redeem at a restaurant
Phones
Edge
Services
Data
App20M phones
Restaurant tillScans QR
CDNShell + status
Waiting roomAdmits 50K/s
GatewayToken + bot checks
Claim serversStateless × 100
Coupon workers8,000 / s
Stock shards100 × 60,000
Claim logDurable
Claims DBBy user id
PushCoupon ready
The numbers, at a glance
6M win14M see “all gone”
≈ 4MEdge
≈ 1MAttempts
50,000Admitted
8,000Coupons
1.25% reaches the backend98.75% answered at the edge
A claim, in order
Happy path for an admitted user. A retry stops at step 4 with the same claim id.
App
Waiting room
Gateway
Claim server
Stock shard
Claim log
Coupon worker
1 join line
2 claim token (when admitted)
3 POST /claims + token
4 verified claim
5 claim script
6 won, claim_id
7 append claim (2 of 3)
8 ack
9 201 won
10 “You got one!”
11 claim → code + push
RequestResponseAsync, does not block
How to count down the stock
The decision this question is really about.
50,000 claims/s
UPDATE … WHERE left > 0
row lock queue
+ Exact and simple.− About 2,000 a second.
50,000 claims/s
DECR stock
one node
+ Atomic and fast.− One core, one failure point.
hash(user_id) % 100
check keydecrementset key
one atomic script
+ 5M ops/s; failures touch 1%.− Rebalance the last burgers.
How it grows
Add a box only when a number forces you to. Highlighted boxes are new at each stage.
App
Claim servers
SQL: stock + claims
App
CDNWaiting roomConfig
Gateway + bot checksClaim servers
SQL: stock + claims
App
CDNWaiting roomConfig
Gateway + bot checksClaim servers
Stock shards × 100Claims DB
AppPush
CDNWaiting roomConfig
Gateway + bot checksClaim serversCoupon workers
Stock shards × 100Claim logClaims DBTills
Was this walkthrough useful?Your vote tells us what to improve next.