Notification Service Design
Difficulty: MEDIUMCategory: LLDFrequency: 1Asked On 2025-01-23
Problem Statement
Design a Notification Service that can send notifications to users through multiple channels such as Email, SMS, Push Notifications, and In-App messages. The service must support reliability, scalability, and extensibility for new channels.
Functional Requirements (FR)
Notification Management
•Send a notification to one or more users.
•Support multiple channels: Email, SMS, Push, In-App.
•Allow bulk notifications (e.g., promotional campaigns).
Channel Abstraction
•Decouple notification logic from specific providers (e.g., Twilio for SMS, Firebase for push).
•Easy integration of new channels in the future.
Retry & Failure Handling
•Retry on transient failures.
•Log permanent failures for monitoring.
Scheduling & Priority
•Support scheduled notifications (send later).
•Assign priority (high, medium, low).
User Preferences
•Allow users to configure notification preferences (e.g., only Email, mute SMS).
Template Management
•Support predefined templates with placeholders (e.g., “Hi {username}, your order {orderId} is shipped”).
Non-Functional Requirements (NFR)
•Scalability: Should handle millions of notifications per day.
•Reliability: Guaranteed delivery with retry mechanisms.
•Extensibility: Easy addition of new notification channels.
•Low Latency: Critical alerts (e.g., OTPs) must be delivered within seconds.
Core Entities / Classes
•Notification: id, userId(s), message, channel, priority, timestamp, status
•Channel (Interface): Implementations: EmailChannel, SMSChannel, PushChannel, InAppChannel
•UserPreferences: userId, preferredChannels, muteSettings
•Template: templateId, content, placeholders
•Scheduler/Queue: For delayed or async delivery.
•RetryPolicy: Handles backoff/retry attempts.
Operations
•sendNotification(notification)
•scheduleNotification(notification, time)
•retryFailedNotification(notificationId)
•registerChannel(channelType, channelImpl)
•applyTemplate(templateId, placeholders)
•getUserPreferences(userId)
Constraints & Considerations
•Use message queues (Kafka/RabbitMQ/SQS) to decouple producers and notification workers.
•Critical flows (e.g., OTP) may bypass queue for direct send.
•Need idempotency to avoid duplicate sends.
•Notifications stored for audit/logging.
✅ This makes a solid LLD problem statement for Notification Service.