Build a Wish-List Price Alert System at Scale
System DesignModel answerLast updated
Design a service where users set a target price on any product and receive a notification the moment the price drops to or below that target.
Build a Wish-List Price Alert System at Scale
You are designing a backend service that monitors product prices across online retailers and notifies users when a product hits their desired price.
What the service does
- A user registers any product by pasting its URL and setting a target price. When the live price drops to or at that target, the user gets an alert (email or push).
- The system periodically fetches the current price of every tracked product from the retailer, either through an official product API or by scraping the page. Scraping anti-bot specifics are out of scope; assume you have a library that handles it.
- Full price history is stored and exposed as a chart (30-day, 1-year, all-time views).
- Users can view, update, and remove their active alerts.
Scale targets
- Tens of millions of users, with an average of 10 tracked products each.
- Millions of unique products in total (many users track the same popular item).
- Popular products should have their price refreshed roughly every hour; obscure ones can wait up to 24 hours.
- Alerts should fire within a few minutes of a price drop being detected, and the same drop must never trigger duplicate notifications.
What a strong answer covers
Walk through your clarifying questions and assumptions, a back-of-envelope estimate, the API surface, data model, and high-level component diagram. Then pick two or three areas to go deep: the fetch scheduling strategy, the alert-matching logic at scale, the price history storage design, or data quality and anomaly detection. For each deep dive, discuss trade-offs and failure modes, not just the happy path.
Hints
Hint 1
Before drawing any boxes, figure out how many fetches per second the system must sustain and what your budget-per-source rate limit implies. That number drives most architectural decisions downstream.
Hint 2
Subscriptions vastly outnumber unique products. Ask yourself: which dimension should you shard on — user or product — and why does the answer differ between the write path and the read path?
Hint 3
A price alert that fires twice is almost as bad as one that never fires. Think through exactly-once semantics end-to-end: what is your deduplication key, where do you store state, and what happens when a Kafka consumer crashes mid-flight?
Model answer
Medium Try it yourself first — then compare your approach, complexity and edge cases.
1. Clarify and Scope
State assumptions out loud before drawing anything.
Functional scope
- User submits a URL and a target price; system normalizes the URL to a canonical product identity (e.g., an Amazon ASIN or a
(domain, product_id)pair). - Prices are polled on a schedule; official batch APIs are preferred over scraping.
- Price history is stored indefinitely; charts are served at raw, daily, and monthly granularities.
- Users can list, edit, and delete their alerts.
Non-functional targets
- 50 M subscriptions across 5 M unique products (10:1 deduplication ratio — this is the key leverage point).
- Freshness: ~1 h for popular products, ~24 h for long-tail.
- Alert latency: under 5 minutes from price-drop detection to notification delivery.
- No duplicate alerts for the same price event.
Back-of-envelope
- Average polling interval ≈ 6 h → 5 M products × 4 polls/day = 20 M fetches/day ≈ 230 fetches/s sustained, ~1 k/s at peak.
- Each price sample ≈ 30 bytes. Storing every sample: ~600 MB/day. Storing only on-change drops this 5–10×.
- Chart reads: ~50 M page views/day ≈ 600 QPS, highly cacheable.
2. API Design
POST /v1/alerts {url, target_price} → {alert_id, product_id}
GET /v1/alerts → list of user's active alerts + current price
PATCH /v1/alerts/{id} {target_price}
DELETE /v1/alerts/{id}
GET /v1/products/{id}/history?range=1y&resolution=1d
POST normalizes the URL, deduplicates into an existing product record if one exists, and schedules an immediate first fetch so the user sees a current price right away.
3. Data Model
| Store | Entity | Key fields |
|---|---|---|
SQL (sharded by product_id) | Product | product_id, source, external_id, title, current_price, last_fetched_at, tracker_count |
SQL (sharded by product_id) | Alert | alert_id, user_id, product_id, target_price, state (ARMED/FIRED), last_alerted_at |
| Secondary index | user_id → alert_ids | powers the "my alerts" list |
| Cassandra / TSDB | PriceHistory | partition = product_id, clustering = ts DESC; columns: price, availability |
| Rollup table | PriceDaily | product_id, date, min, max, close |
| Redis sorted set | FetchSchedule | member = product_id, score = next_fetch_unix_ts |
Shard alerts by product_id, not user_id. The hot path is "product P just changed price — who needs an alert?" That lookup must hit a single shard. The user-facing list uses the secondary index and is read infrequently enough that cross-shard scatter is acceptable.
4. Component Architecture
Users ──► API Gateway
│
┌────────┴──────────┐
Tracking svc Chart svc ──► CDN
│ │
Products/Alerts DB PriceHistory + Rollups
│
Scheduler
(Redis ZSET, sharded by source)
│ due product_ids
▼
Fetch Queue (Kafka, partitioned by source domain)
▼
Fetcher workers ←── per-source rate limiter (token bucket in Redis)
│
price-events topic
├──► History writer (append on change; compute rollups)
├──► Product updater (current_price, reschedule next fetch)
└──► Alert matcher ──► Notification svc (email / push)
Decoupling through Kafka means a slow email provider never backs up the fetch pipeline.
5. Deep Dives
Scheduling: Staying Fresh Within a Fetch Budget
Rate limits from retailers are the hard constraint. Allocate the budget by value:
- Compute a dynamic interval:
interval = f(tracker_count, price_volatility, proximity_to_thresholds). A product with 10 k trackers and a price that fluctuates daily gets hourly polls. A product with one tracker and a stable price for six months gets daily polls. - Threshold proximity boost. If the live price is within 5 % of any user's target, cut the interval in half. This is cheap to check since you store
min_armed_targetper product. - Scheduler workers pop due items with
ZRANGEBYSCORE 0 <now> LIMIT N, enqueue them to Kafka, then rewrite the score tonow + intervalas a lease. If the fetch worker crashes before acknowledging, the lease score stays in the past and the item reappears naturally. - Partition the fetch queue by source domain so you can apply independent token buckets per retailer without one slow domain stalling others.
Alert Matching Without Scanning 50 M Rows
When product P drops from old_price to new_price, the users to notify are those with an ARMED alert where target_price falls in [new_price, old_price).
- Because alerts are sharded by
product_id, this is a range scan on a single shard:WHERE product_id = P AND state = 'ARMED' AND target_price >= new_price. This is fast. - Short-circuit with a cached max. Store
max_armed_targetper product in Redis. Ifnew_price > max_armed_target, skip the DB query entirely. Most price events trigger no alerts, so this eliminates the majority of scans. - Hysteresis. After firing, set
state = FIRED. Re-arm only when the price rises back above the target (plus an optional margin). This prevents flapping — a price that bounces repeatedly around a threshold does not spam the user. - Exactly-once delivery. The deduplication key is
(alert_id, price_event_id). Kafka delivers at-least-once; the notification service checks this key in a dedupe table (Redis with a TTL) before sending. A crash between "mark as fired" and "send email" is safe because the idempotency check catches the retry. - Hot products. A viral deal might have 500 k armed alerts. The matcher pages through results in batches and fans out work to a separate notification queue. Per-user send-rate limits and digest grouping (one email listing several drops) protect deliverability and sender reputation.
Price History and Charts
- Write a history row only when price or availability changes. Store a lightweight heartbeat separately so the chart can confidently draw a flat line for stable periods, rather than showing a gap.
- Serve charts from rollups: raw rows for the last 30 days, daily min/max/close for anything older. A one-year chart is then 365 points read from a single Cassandra partition — fast and predictable.
- Past days are immutable. Cache chart responses in Redis and at the CDN keyed by
(product_id, range, resolution)with a short TTL, and invalidate on any price change. - After 90 days, compact raw rows into daily rollups and archive to object storage (Parquet on S3) for analytics queries.
Data Quality
Scraped prices are unreliable. Common failure modes: currency parsing errors, $0.01 placeholder prices for out-of-stock items, third-party marketplace prices leaking in, and HTML structure changes returning garbage.
- Validate each incoming price against recent history. A drop larger than 90 % from the trailing 7-day average is anomalous.
- For anomalous readings, re-fetch once to confirm before writing to history or triggering any alerts. A 10-minute delay is far less damaging than a false alert.
- Track per-source error rates. If a source returns parse failures on more than 5 % of requests over a 15-minute window, pause its fetch queue and page on-call rather than hammering a broken page.
Common Mistakes to Avoid
- Sharding subscriptions by user makes the hot path (find all alerts for product P) a fan-out across every shard. Always shard by
product_id. - Polling every product on the same schedule wastes budget on dead products and under-serves popular ones. Dynamic intervals are essential at this scale.
- Skipping hysteresis on alerts leads to notification storms when prices oscillate, which damages user trust and email sender reputation quickly.
- Trusting scraped prices without validation will fire false alerts on data-entry errors. A confirmation re-fetch is cheap insurance.