Design a Product Price Monitor with Alerts
System DesignModel answerLast updated
Build a scalable service that tracks prices across e-commerce sites, stores historical data, and notifies users when prices drop below their thresholds.
You need to architect a service that monitors product prices from online retailers. Users paste product URLs into your platform, view price trends over time, and configure alerts that trigger when prices fall to their desired level.
Your architecture must handle:
- Processing incoming product URLs and identifying what they refer to
- Collecting price data regularly for millions of items
- Storing and serving price history efficiently
- Managing user alert rules and delivering timely notifications
- Avoiding redundant work when multiple users watch identical products
- Balancing cost, latency, and data freshness at scale
Walk through your design choices, explaining the tradeoffs and how each component addresses the requirements.
Hints
Hint 1
Start by defining concrete scale numbers: how many users, products, and price checks per day? This anchors all downstream decisions.
Hint 2
The same product appears under many different URLs. Solving canonicalization early prevents duplicate tracking and wasted fetches.
Hint 3
Not all products need the same refresh rate. Think about how to prioritize popular items or those close to user alert thresholds.
Model answer
Medium Try it yourself first — then compare your approach, complexity and edge cases.
Model Answer: Product Price Monitor Design
1. Requirements and Scale
What the system does:
- Accept product URLs from users and begin monitoring them
- Display historical price graphs
- Send notifications when prices cross user-defined thresholds
- Let users manage their watchlists and alert settings
Performance and reliability targets:
- Popular items refresh every hour; less popular ones refresh daily
- Alerts deliver within minutes of detecting a price drop
- No duplicate alerts, no missed threshold crossings
- Read operations (viewing history) stay available even if collection lags
Scale estimates:
- 20 million users, 100 million (user, product) watchlist entries
- 20 million distinct products after deduplication
- Hot tier: 5 million products checked hourly → ~1,400 checks/second average
- Cold tier: 15 million products checked daily → ~175 checks/second average
- Peak load reaches 5,000 checks/second
- Price changes are infrequent (a few per week per product), so storing only deltas keeps storage under a few GB/week
2. Core APIs
POST /trackings {url, target_price, currency} → {tracking_id, product_id}
GET /trackings → user's watchlist with current prices
PATCH /trackings/{id} {target_price, enabled}
DELETE /trackings/{id}
GET /products/{id}/history ?from=...&to=...&granularity=... → [{timestamp, price, available}]
The POST endpoint is idempotent: submitting the same product twice returns the existing tracking entry rather than creating duplicates.
3. Data Schema
Products table (partitioned by product_id):
- Derived ID like
platform:region:item_code - Fields: canonical URL, name, thumbnail, currency, latest price, availability, last fetched, next fetch time, popularity tier, number of watchers
User trackings (partitioned by user_id):
- Fields: tracking ID, user ID, product ID, target price, alert status (active or triggered), last notified price, creation timestamp
Alert index (partitioned by product_id):
- Sorted entries:
(product_id, target_price, tracking_id) - When a product drops to price P, a range query finds all active alerts where
target_price >= P - Built from the trackings table via change data capture
Price timeseries (e.g., Cassandra or TimescaleDB):
- Partition by
product_id, sort by timestamp - Only write when price or availability changes, plus a metadata update on the product row for "last checked"
- Pre-aggregate daily min/max for long-range queries
4. Architecture Overview
Users → API Layer → Tracking Service → Tracking DB
↓ ↓ (CDC)
URL Resolver Alert Index
↓
Product Catalog
Scheduler (sharded) → Fetch Queue (Kafka, keyed by product_id)
↓
Fetcher Pool (rate-limited, using official APIs where available)
↓
Parser → Change Detector → Price History Store
→ Product DB (update current state)
→ Event Stream (Kafka) → Alert Matcher
→ Notification Service → Push/Email
5. Key Design Decisions
Canonicalizing URLs
The same product has countless URL variations: tracking parameters, affiliate codes, mobile subdomains, redirects. Resolve them in stages:
- Normalize syntax: follow redirects (with caching), lowercase host, map mobile domains
- Extract stable identifier using per-retailer regex patterns (e.g.,
/item/{sku}) - If no ID in URL, fetch the page once and parse meta tags or structured data
- Build canonical key:
retailer + region + identifier
This ensures 50,000 users tracking the same product result in one database row and one scheduled fetch, not 50,000. The product's watcher count increments; per-user state stays in the tracking records.
Scheduling Millions of Fetches
Avoid scanning the entire product table every minute. Instead:
- Shard products across multiple scheduler instances by hashing
product_id - Each shard maintains a priority queue or time-bucketed index (Redis sorted sets work well)
- Products have a
next_check_attimestamp computed from:- Watcher count
- Recent price volatility
- Proximity to nearest alert threshold (a product $0.50 above a target deserves faster checks)
- Calendar events like holiday sales
- Items that rarely change or are out of stock back off exponentially, capped at 24 hours
- Add jitter to prevent load spikes at round timestamps
This keeps fetch volume proportional to actual value delivered.
Fetching at Scale
The fetcher is the highest-risk component operationally:
Prefer official APIs. Use the retailer's product API or affiliate data feed first—batch endpoints often return 10+ products per call, reducing request volume by an order of magnitude. Only scrape pages when terms permit and APIs are unavailable.
Rate limit globally. Use token buckets per retailer and per API credential, enforced in a shared rate limiter service. When quota exhausts, gracefully degrade by stretching refresh intervals for cold-tier products first.
Validate outputs. Run per-retailer parsers and sanity-check results: price must be positive, currency must match, and changes exceeding 90% trigger a recheck before alerting. Circuit breakers halt fetching when parse failure rates spike, preventing bad data from propagating.
Handle failures. Transient errors (5xx, timeouts) retry with exponential backoff. Permanent errors (404, item delisted) mark the product inactive after confirmation. Dead letter queues capture parse failures for manual review.
Storing and Querying Price History
Write to a time-series database partitioned by product_id:
- Only insert when price or availability changes; store "last checked" metadata separately
- This compresses a flat period into zero rows while preserving "the price was X from time A to B" semantics
- For dashboard queries spanning months, precompute daily rollups (min/max/close) asynchronously
- Cache recent history (last 90 days) in Redis for hot products to serve charts without hitting the database
Typical query: "show daily prices for the last year" hits the rollup table, not raw observations.
Matching Alerts and Sending Notifications
When a price drops, the change detector publishes an event. The alert matcher:
- Queries the alert index for
product_idwheretarget_price >= new_price AND status = ACTIVE - Marks matched alerts as triggered and records
last_notified_price - Enqueues notifications with user preferences (push, email, quiet hours)
The notification service:
- Deduplicates rapid successive drops (e.g., multiple fetches within minutes)
- Rate-limits per user (max N alerts per hour)
- Tracks delivery status and retries on transient failures
- Does not rearm alerts automatically; users must explicitly re-enable them after acknowledging
Handling Edge Cases
Sudden availability changes. When an out-of-stock product returns, notify users even if the price hasn't changed, since availability is often as important as price.
Currency fluctuations. Store prices in the original currency. If displaying in a different currency, apply exchange rates client-side and note the conversion date.
Retailer API changes. Version parsers per retailer. When a parser update is needed, run both old and new versions in shadow mode, compare outputs, and switch over after validating accuracy.
User churn. Periodically sweep products with zero active watchers and archive their history to cold storage. Stop scheduling fetches for them.
6. Complexity and Tradeoffs
Time complexity:
- Inserting a tracking: O(1) for URL resolution cache hit, O(log W) to update alert index where W is watchers per product
- Fetching and parsing: O(P) where P is products due this cycle
- Alert matching: O(A) where A is alerts for a product, bounded by watcher count
- History query: O(log N + K) where N is partition size and K is points returned
Space:
- Product metadata: 20M × ~500 bytes ≈ 10 GB
- Trackings: 100M × ~100 bytes ≈ 10 GB
- Price history (deltas only): 20M products × 3 changes/week × 30 bytes × 52 weeks ≈ 90 GB/year raw, much less with rollups
- Alert index: same magnitude as trackings
Tradeoffs made:
- Eventual consistency: A user might see stale prices on their dashboard for a few minutes if the cache hasn't updated. Acceptable because price changes are infrequent.
- Best-effort alerting: Network issues or notification service outages might delay alerts by minutes. We prioritize no duplicate spam over absolute latency.
- Fetch prioritization: Cold-tier products trade freshness (24h delay) for cost. Users accept this for niche items.
- API dependence: Relying on retailer APIs means sudden changes can break ingestion. Versioned parsers and monitoring mitigate this.
Common mistakes to avoid:
- Scanning all products every cycle instead of using scheduled timestamps
- Not deduplicating products, leading to redundant fetches
- Sending alerts on every fetch instead of only on threshold crossings
- Storing every observation instead of deltas, exploding storage costs
- Ignoring rate limits and getting API keys revoked
- Not validating parsed prices, letting garbage data trigger false alerts
This design scales to hundreds of millions of products by sharding work, batching fetches, storing only deltas, and tiering refresh rates based on value delivered to users.