Design a Scalable Notification System for Lineup Alerts (Kafka-based)

Difficulty: MEDIUMCategory: HLDFrequency: 1Asked On 2024-04-29

Problem Statement

Design a real-time notification system that sends lineup alerts to users 30 minutes before a sports match. The system will consume live events from Kafka streams, process them, and trigger notifications (push, SMS, email, in-app) at scale. The challenge is to ensure timely delivery, high throughput, and fault tolerance.


✅ Functional Requirements

1.<span></span>Event Ingestion (Kafka-based)
2.<span></span>Consume match schedule and lineup events from Kafka topics.
3.<span></span>Detect when a lineup is published for an upcoming match.
4.<span></span>Notification Scheduling
5.<span></span>Schedule an alert 30 minutes before the match start time.
6.<span></span>Support retries if a notification fails.
7.<span></span>Multi-Channel Delivery
8.<span></span>Push notifications (FCM/APNs).
9.<span></span>Email notifications.
10.<span></span>SMS notifications.
11.<span></span>In-app alerts.
12.<span></span>User Targeting & Preferences
13.<span></span>Notify only subscribed users (e.g., fans of a team).
14.<span></span>Respect user preferences (channel selection, quiet hours).
15.<span></span>Scalability & Monitoring
16.<span></span>Handle millions of notifications per match day.
17.<span></span>Track success/failure rates, retries, and latency.


⚙️ Non-Functional Requirements

1.<span></span>Low Latency → notifications should be scheduled within seconds of lineup ingestion.
2.<span></span>High Throughput → handle 5M+ users per major tournament.
3.<span></span>Reliability → no missed alerts; retries on channel failures.
4.<span></span>Scalability → horizontally scalable consumers, schedulers, and delivery workers.
5.<span></span>Fault Tolerance → Kafka, schedulers, and delivery services should recover gracefully.


🔐 Constraints

1.<span></span>Kafka streams publish lineup events in real time.
2.<span></span>Users may belong to millions of different fan segments.
3.<span></span>Notifications must go out 30 minutes before match start, not earlier or later.
4.<span></span>Delivery guarantees → at least once (no missed notifications, duplicates acceptable).


🧱 Key Components to Design

1.<span></span>Kafka Consumer Service
2.<span></span>Subscribes to lineup events.
3.<span></span>Extracts match ID, start time, and teams.
4.<span></span>Notification Scheduler Service
5.<span></span>Stores job in a distributed scheduler (e.g., Quartz, Kubernetes CronJob, or Redis-based delay queue).
6.<span></span>Triggers 30 minutes before match start.
7.<span></span>User Segmentation Service
8.<span></span>Finds users who follow the match/team.
9.<span></span>Filters based on notification preferences.
10.<span></span>Notification Orchestrator
11.<span></span>Pushes notification tasks into a queue (Redis/Kafka).
12.<span></span>Deduplicates repeated lineup alerts.
13.<span></span>Delivery Workers
14.<span></span>Consume from queue and send notifications via:
15.<span></span>Push Service (FCM/APNs)
16.<span></span>Email Service (SMTP/SendGrid)
17.<span></span>SMS Service (Twilio, Karix)
18.<span></span>In-app messages
19.<span></span>Retry & DLQ (Dead Letter Queue)
20.<span></span>Handles failed notifications.
21.<span></span>Retries with exponential backoff.
22.<span></span>Monitoring & Analytics Service
23.<span></span>Tracks delivery success rates, failures, retries.
24.<span></span>Provides dashboards for latency & throughput.


🧪 Example Flow

<div><div><br /></div><div>1. Kafka publishes lineup event → “Match A starts at 6:00 PM, lineup announced.”</div><div>2. Kafka Consumer ingests event → extracts start time.</div><div>3. Scheduler creates job → trigger at 5:30 PM.</div><div>4. At 5:30 PM → User Segmentation fetches fans of Match A.</div><div>5. Orchestrator pushes notifications into Redis/Kafka queue.</div><div>6. Delivery workers consume queue → send push/email/SMS.</div><div>7. Failed notifications go to Retry queue or DLQ.</div><div>8. Monitoring tracks delivery stats in real-time dashboard.</div></div>


Solution

Comments