Skip to content
SD-30 · Back to the write-up

Design a Price Alerts

React to each price change on a stream, find the alerts it meets with one range read, mark them fired, and let a queue of senders deliver each one once.

Follow a request

Sources
API and stream
Matching
Data and delivery
ShopperApp or web
Pricing serviceEvery change
Alert APICreate, list
Price streamKeyed by product
MatchersRange read, fire
Notify queueJobs to send
Alert DB8 shards by product
Send logDedupe, caps
SendersPush and email
Push + emailProviders
1pricing → stream · p_77: 349 → 299The pricing service publishes the change, with the old and new price and a version.1 / 7

The numbers, at a glance

On sale day, of every 5 price changes……about 1 meets someone’s target
1 fires ≈ 10,000/s4 fire nothing
Sale day is 10× the peakPrice changes per second
Polling is mostly wastedAlerts that fire on a normal day
So we react to changes, and read only the alerts a change meets.

A price drop, in order

The matcher commits its stream offset only after the jobs are on the queue, so a crash means a retry, never a lost alert.

Pricing service
Price stream
Matcher
Alert shard
Notify queue
Sender
Provider
1 p_77: 349 → 299, v=812
2 poll partition 12
3 change
4 UPDATE armed → fired, target ≥ 299
5 3 alerts
6 3 jobs
7 commit offset
8 receive job
9 push, collapse key a_91
10 accepted
11 delete job
RequestResponseAsync, does not block

How a change finds its alerts

The decision this question is really about.

Poll every alert
Wasteful
every 5 min
scan 200M alerts
up to 5 min late
+ Simple.− Reads 200 million rows to find a few.
Range read per change
Our pick
p_77 → €299
index: product 77, armed, target ≥ 299
fire 3, enqueue 3
+ Work grows with changes, not alerts.− Big drops return many rows: page them.
Thresholds in memory
For hot products
sorted targets per product
binary search
still fire through the shard
+ Microseconds per change.− Rebuild 200M alerts on every restart.

How it grows

Add a box only when a number forces you to. Highlighted boxes are new at each stage.

Stage 1 · ≈ 1 million alertsMake it work
ShopperPricing service
Alert APIPoller job
Alert DBEmail provider
A job polls every alert every 5 minutes and emails inline.
Stage 2 · ≈ 5,000 changes/sReact to changes
ShopperPricing service
Alert APIPrice stream
Matchers
Alert DB + indexPush + email
A price stream, matchers and a range index on target price.
Stage 3 · ≈ 50,000 changes/sSurvive sale day
ShopperPricing service
Alert APIPrice stream
MatchersNotify queueSenders
8 alert shardsPush + email
Sending moves to a queue; alerts split into 8 shards by product.
Stage 4 · 50,000 changes/s, 10,000 alerts/sDon’t spam
ShopperPricing service
Alert APIPrice stream
MatchersNotify queueSenders
8 alert shardsSend logPush + email
Fire once with a 5% re-arm margin, a send log, a daily cap.
Was this walkthrough useful?Your vote tells us what to improve next.