Amazon Notification Service design

Difficulty: MEDIUMCategory: LLDFrequency: 1Asked On 2025-03-18

Problem Statement

Design the Low-Level Design (LLD) for a Notification Service similar to what Amazon or large-scale e-commerce systems use.


This service is responsible for sending notifications to users across multiple channels — such as Email, SMS, Push, or In-App alerts — based on system events like order updates, payment success, shipment status, etc.


The goal is to design a modular, extensible, and event-driven notification system.


🎯 Goal


Design a notification service that can:


•Receive notification requests from multiple internal systems (e.g., order service, payment service).
•Support multiple channels (Email, SMS, Push, In-App).
•Allow customizable templates and user preferences.
•Ensure reliable delivery and retries on failure.
•Maintain audit logs and delivery status for traceability.


✅ Functional Requirements


1. Notification Request Handling


•The system receives a notification event (e.g., “Order Shipped”, “Payment Successful”) containing:
•User ID
•Message type (ORDER, PAYMENT, etc.)
•Channel(s) to notify (Email/SMS/Push)
•Message metadata (template ID, dynamic placeholders)


2. Channel-Specific Delivery


•The service should support multiple delivery channels, such as:
•EmailNotificationService
•SMSNotificationService
•PushNotificationService
•InAppNotificationService
•Each channel implements a common interface to send notifications.


3. Notification Templates


•Messages should be based on templates:
•Templates contain placeholders (e.g., {userName}, {orderId}).
•System replaces them dynamically before sending.


Example:

1 2"Hello {userName}, your order {orderId} has been shipped!"


4. User Preferences


•Users can choose which notifications to receive:
•e.g., only Email for marketing, SMS for orders.
•Service must respect these preferences when sending notifications.


5. Retry and Failure Handling


•If a notification fails (e.g., email server timeout), the system should:
•Retry based on configurable policy (e.g., up to 3 times).
•Log the failure reason and mark as “FAILED” if all retries exhausted.


6. Audit and Tracking


•Maintain logs for:
•Sent notifications (user, type, channel)
•Delivery status (SUCCESS / FAILED / RETRYING)
•Timestamps for each attempt


⚙️ Non-Functional Requirements


•Scalable to handle thousands of notifications per second.
•Thread-safe and asynchronous processing.
•Extensible — new channels (like WhatsApp or Slack) can be added easily.
•Reliable — no notification should be lost.
•Low latency for user-facing events (order confirmations).


🧱 Key Classes to Design


ClassResponsibility


Notification


Represents a notification request with metadata.


NotificationChannel (interface)


Defines the sendNotification() contract for all channels.


EmailNotificationService


Sends email notifications.


SMSNotificationService


Sends SMS notifications.


PushNotificationService


Sends push/in-app alerts.


NotificationManager


Core orchestrator that routes notifications to proper channels.


TemplateEngine


Populates dynamic message templates with actual data.


UserPreferenceService


Retrieves user’s preferred notification channels.


RetryPolicy


Handles retry logic for failed notifications.


NotificationRepository


Logs and tracks notification events and delivery status.


🧩 Example Class Relationships

1 2Notification 3 ├── notificationId 4 ├── userId 5 ├── type (ORDER, PAYMENT, PROMOTION) 6 ├── List<ChannelType> (EMAIL, SMS) 7 ├── templateId 8 ├── data (Map<String, String>) 9 ├── status (PENDING, SENT, FAILED) 10 11NotificationManager 12 ├── processNotification(Notification) 13 ├── sendToChannels(List<NotificationChannel>) 14 15NotificationChannel (Interface) 16 ├── send(Notification notification) 17 18EmailNotificationService implements NotificationChannel 19 ├── send(Notification) 20 21SMSNotificationService implements NotificationChannel 22 ├── send(Notification) 23 24TemplateEngine 25 ├── render(templateId, data)


🔄 Example Flow


🧾 Order Shipped Event


1.Order Service sends event → NotificationManager
1 2{ 3 "userId": 123, 4 "type": "ORDER_SHIPPED", 5 "templateId": "T001", 6 "channels": ["EMAIL", "SMS"], 7 "data": {"userName": "Sahil", "orderId": "ORD678"} 8}


NotificationManager:


•Fetches user preferences.
•Loads template → replaces placeholders.
•Sends via EmailNotificationService and SMSNotificationService.
•Logs delivery status.



2. EmailNotificationService → calls email API.

3. SMSNotificationService → calls SMS provider.

4. NotificationRepository → logs results.


🧪 Example Output

1 2{ 3 "notificationId": "N-456", 4 "userId": "123", 5 "channels": ["EMAIL", "SMS"], 6 "status": "SENT", 7 "timestamp": "2025-10-24T12:15:00Z" 8}


🔐 Concurrency & Reliability


•Each notification handled asynchronously (e.g., via a queue).
•Channel sends are independent — failure in one doesn’t block others.
•Implement retry queue for temporary failures.


🧠 Possible Extensions


•Add priority levels for urgent notifications.
•Add campaign notifications for bulk marketing messages.
•Add internationalization (i18n) support for templates.
•Add analytics on open rates, delivery rates, etc.
•Add scheduling (send later).


✅ Final Summary:


Design a Notification Service (LLD) that supports:


•Sending notifications via multiple channels,
•Handling templates, retries, and user preferences,
•Logging delivery status and ensuring reliability,
•Extensible architecture for future channels and events.


Focus on object design, interface-driven structure, and notification orchestration logic, not on scaling or infrastructure.

Solution

Comments