SYSTEM DESIGN SKETCHBOOK / PRACTICE SHEET / NO. 30
Design price drop alerts
On a large shopping site, people tap "alert me" on a product they want and set a target price, or ask to hear about any drop of 10% or more. Prices change constantly as sellers reprice and sales start. A good alert arrives while the deal is still live and arrives once; a spammy or late one teaches people to ignore them.
Requirements
- Create, edit and delete an alert on a product with a target price or a percentage drop.
- When a price change brings the price at or below an alert's target, notify that user by push or email.
- Notify at most once per crossing: an alert fires again only after the price has gone back up and crossed down again.
- Users can see which of their alerts have fired; alerts expire after 180 days.
Constraints and assumptions
- 200 million active alerts across 50 million products; 30 million users have at least one alert.
- 20 million price changes a day, but sale events reprice up to 1 million products within a few minutes.
- A notification should go out within 5 minutes of the price change.
- Popularity is skewed: a hot console or phone can have 2 million alerts on one product.
- An existing notification service delivers push and email given a user id, a message and an idempotency key.
Out of scope for the first sketch
Price history charts · Tracking prices on other websites · Delivery internals of push and email
Draw your design
Rough math and notes
SYSTEM DESIGN SKETCHBOOK / FOLLOW-UPS
Design price drop alerts
Finish your first sketch before answering these. Cross out freely.
- A price changes. How do you find which of the 200 million alerts care about it, without scanning them?
- A console with 2 million alerts drops from $499 to $399. Walk through what happens next, including the load on the notification service.
- A repricing bot flips a price between $99 and $101 every few minutes, around many users' $100 targets. How do you avoid spamming them?
- Your matcher crashes after notifying half of the users for one price change. What happens when it restarts?
- Now add stock alerts: 8,000 symbols, 10,000 price ticks per second, and notifications within 2 seconds. What changes?
Compare afterwards: worked approaches and reading at sketchbook /questions/price-alerts/review