Design a Price Alert & Promotion Tracking Service

Difficulty: MEDIUMCategory: HLDFrequency: 1Asked On 2025-06-12

Problem Statement

Design a highly scalable system that enables users to track product prices across e-commerce platforms and receive real-time alerts when the price of a product drops or increases, or when new promotions become available.


The system should support millions of users, handle continuous price updates from multiple sources, and provide efficient notifications through multiple channels (email, SMS, push notifications).


🎯 Core Requirements


1. User Operations


•Users should be able to:
•Register and authenticate.
•Add products to their watchlist.
•Set desired price thresholds for alerts.
•Choose preferred notification channels (email, SMS, app notification).


2. Product and Promotion Tracking


•The system should:
•Periodically fetch current prices and promotions from multiple e-commerce sites or APIs.
•Detect price changes or promotion updates.
•Store historical price data for analytics and trends.


3. Alert and Notification


•When a product’s price drops below or rises above a user’s configured threshold:
•Generate an alert.
•Send a notification through the user’s preferred channels.
•Support batch notifications to avoid spam.
•Track which notifications have been sent to avoid duplicates.


4. Scalability and Performance


•The system should efficiently handle:
•Millions of product prices.
•Continuous polling or streaming updates.
•High-volume alerts and mass notifications.
•Ensure low latency between a price change and user notification.


5. Non-Functional Requirements


•Availability: 99.9% uptime.
•Latency: <2 minutes delay between price update and notification.
•Durability: Maintain consistent product data and user preferences.
•Scalability: Horizontal scaling for crawlers, storage, and notifications.
•Security: Authenticated API access and secure user data handling.


⚙️ Core Functional Components


ComponentResponsibility


User Service


Manage user profiles, preferences, and watchlists.


Product Service


Store and retrieve product metadata and pricing info.


Price Tracker / Crawler Service


Continuously fetch price data from sources (Amazon, Flipkart, etc.).


Price Change Detector


Compare new prices with stored ones to detect changes.


Alert Engine


Determine which users need to be notified based on their thresholds.


Notification Service


Send alerts via email, SMS, or push notifications.


Promotion Service


Track and surface ongoing promotions or deals.


Analytics Service


Store price history and generate insights/trends.


🧱 High-Level Data Model


User

1 2User { 3 user_id: UUID 4 email: string 5 phone: string 6 preferences: { notify_email: true, notify_sms: false } 7}


Product

1 2Product { 3 product_id: UUID 4 name: string 5 url: string 6 current_price: float 7 last_updated: timestamp 8}


UserWatchlist

1 2UserWatchlist { 3 user_id: UUID 4 product_id: UUID 5 desired_price: float 6 alert_sent: boolean 7}


PriceHistory

1 2PriceHistory { 3 product_id: UUID 4 timestamp: datetime 5 price: float 6}


Promotion

1 2Promotion { 3 promo_id: UUID 4 product_id: UUID 5 description: string 6 valid_till: datetime 7}


🧩 High-Level Architecture

1 2 +--------------------+ 3 | API Gateway | 4 +--------------------+ 5 | 6 +-----------------------------------------+ 7 | Backend Layer | 8 +-----------------------------------------+ 9 | User Service | Product Service | 10 |--------------------------|----------------------| 11 | Price Tracker Service | Price Detector | 12 | Alert Engine | Promotion Service | 13 | Notification Service | Analytics Service | 14 +-----------------------------------------+ 15 | 16 +--------------------+ 17 | Message Queue | 18 | (Kafka/SQS) | 19 +--------------------+ 20 | 21 +--------------------+ 22 | Data Layer (DBs) | 23 +--------------------+ 24 | 25 +------------------------------------+ 26 | SQL/NoSQL | Redis Cache | Blob Storage | 27 +------------------------------------+


🧠 Key Design Considerations


1. Data Collection


•Use web crawlers or API integrations for each supported e-commerce site.
•Crawlers can run on a scheduler (e.g., every 15 minutes).
•Use distributed crawling to scale horizontally.


2. Price Change Detection


•Use a Price Detector that:
•Compares new and old prices.
•Publishes events like PRICE_DROP or PRICE_INCREASE to a message queue.


3. Alert Generation


•Alert Engine subscribes to the queue and identifies all users whose watchlist matches the event.
•Generate and enqueue alert notifications.


4. Notification Delivery


Notification Service processes alerts and sends:

•Email → via SES / SendGrid.
•SMS → via Twilio.
•Push → via FCM or WebSocket.
•Maintain a deduplication cache (Redis) to prevent spam.


5. Scalability


•Use Kafka / AWS SQS for event-driven decoupling.
•Use Redis for caching product prices and user watchlists.
•Shard product data based on product ID or source site.
•Store historical price data in time-series DB (e.g., InfluxDB).


📈 Example Flow


1. User adds a product

1 2User → /addWatch → UserWatchlist 3Product data stored or fetched from external site


2. Price Update Detected

1 2Crawler fetches latest prices → Price Detector 3→ detects drop from ₹1200 → ₹950 → sends PRICE_DROP event to Kafka


3. Alert Generation

1 2Alert Engine consumes event → finds users watching product 3→ triggers notification event


4. Notification Delivery

1 2Notification Service → sends email/SMS → logs alert → marks alert_sent = true


🧱 Storage Choices


Data TypeSuggested StorageReason


User & Watchlist


RDBMS (PostgreSQL/MySQL)


Strong consistency


Product & Price


NoSQL (Cassandra/DynamoDB)


High write throughput


Price History


Time-series DB


Fast range queries


Promotions


Document store (MongoDB)


Flexible metadata


Cache


Redis


Fast lookups


Queue


Kafka/SQS


Asynchronous communication


⚙️ Key APIs


APIDescription


POST /users/register


Create a new user.


POST /watchlist


Add a product to user’s watchlist.


GET /watchlist


Retrieve user’s tracked products.


POST /alerts/subscribe


Enable/disable alert channels.


GET /promotions


Fetch active promotions.


🚀 Scalability Enhancements


•Batch crawlers to limit API calls.
•Stream updates via Kafka → consumers update caches.
•Use rate limiting to protect upstream sources.
•Precompute trending products (most watched / most dropped).
•Add multi-region deployments for global users.


✅ Goal:


Design a real-time, event-driven price alert system that allows users to track product prices, detect promotions, and receive timely alerts when prices change — with scalability, reliability, and low-latency guarantees.

Solution

Comments