Design a Notification Service

Difficulty: MEDIUMCategory: HLDFrequency: 1Asked On 2025-01-23

Problem Statement

Design a high-level system that can send notifications to users across multiple channels (email, SMS, push notifications) in a scalable, reliable, and low-latency manner. The service should support high throughput, user preferences, and failure handling.


Functional Requirements (FR)


Multi-Channel Notifications


•Send notifications via Email, SMS, Push, and optionally in-app.
•Support different templates for messages.


User Preferences


•Users can choose preferred channels.
•Allow opt-in/opt-out for specific types of notifications.


Notification Scheduling


•Support immediate notifications.
•Support scheduled notifications for future delivery.


Retry & Failure Handling


•Retry failed notifications with exponential backoff.
•Log failures and provide alerting for persistent issues.


Bulk Notifications


•Support sending notifications to large user segments efficiently.


Analytics & Monitoring

•Track delivery status: sent, delivered, failed.
•Monitor system health and performance.


Non-Functional Requirements (NFR)


•Scalability: Handle millions of notifications per day.
•High Availability: System should be operational 24/7.
•Low Latency: Notifications must be delivered in near real-time.
•Reliability: Ensure exactly-once or at-least-once delivery semantics.
•Extensibility: Easily add new channels in the future.


Core Components


API Layer

•Accept notification requests: immediate or scheduled.
•Validate requests and user preferences.

Notification Queue / Broker

•Use a message queue (Kafka, RabbitMQ, SQS) to decouple request ingestion and delivery.
•Ensure retries and message durability.

Scheduler Service

•Schedule future notifications based on timing requirements.
•Push scheduled notifications into the queue at the right time.

Delivery Service / Worker

•Pick notifications from the queue.
•Route to appropriate channel service (Email, SMS, Push).

Channel Services

•Email Service: SMTP or third-party API integration.
•SMS Service: Integration with SMS gateway.
•Push Service: Integration with FCM/APNs.

Database / Storage

•Store notification metadata: userId, type, content, status, timestamps.
•Maintain user preferences and opt-in/opt-out settings.

Monitoring & Analytics

•Track delivery success/failure, latency, throughput.
•Generate dashboards for operational visibility.


High-Level Data Flow


1.Client / Application → API Layer → Validates notification request.
2.Push request → Notification Queue.
3.Worker / Delivery Service → Pulls from queue → Determines channel → Sends notification via Channel Service.
4.Channel Service → Sends notification → Updates status in Database.
5.Monitoring & Analytics system → Tracks delivery metrics and alerts.


Design Considerations


•Use asynchronous processing with queues to handle high throughput.
•Ensure idempotency to avoid duplicate notifications.
•Implement backoff and retries for failed deliveries.
•Partition queues based on channel or user segment for parallelism.
•Use caching for user preferences to reduce DB hits.
•Optional: Support prioritization for critical notifications.


✅ This is a complete HLD Problem Statement for a Notification Service, covering modules, data flow, scalability, reliability, and extensibility.

Solution

Comments