Design a Notification Service
Problem Statement
Design a scalable, fault-tolerant Notification Service that can send notifications to users across multiple channels such as Email, SMS, Push notifications, and In-App alerts.
The system should allow other services or applications (e.g., e-commerce, banking, social media) to trigger notifications through an API and should handle high throughput, retries,
scheduling, and user preferences efficiently.
🎯 Core Requirements
Functional Requirements
Notification Triggers
Multi-Channel Support
User Preferences
Retries & Failures
Delivery Tracking
Template Management
Scalability
Extensibility
⚙️ Non-Functional Requirements
AttributeRequirement
Availability
99.9%
Latency
< 2 seconds per notification
Durability
Guaranteed delivery (eventual)
Scalability
Handle millions of events/day
Security
Encrypt sensitive data (email, phone), OAuth for APIs
Compliance
GDPR, DND, and audit logging
🧩 Core Components
Component with Description
Notification Producer (Trigger)
Other systems (Order Service, Payment Service) send notification events to the service via REST or message queues.
Notification Orchestrator
Central controller that receives requests, validates, enriches data, and routes them to the correct channel.
Message Queue (Kafka/SQS)
Decouples producers and consumers; ensures durability and fault-tolerance.
Channel Services
Dedicated microservices for Email, SMS, Push, etc. Handle integration with 3rd-party providers.
Template Service
Stores and renders message templates dynamically.
User Preference Service
Stores user preferences and DND settings.
Notification Store
Tracks delivery status, retries, and logs.
Scheduler / Retry Manager
Handles delayed or scheduled notifications.
API Gateway
Entry point for external services to trigger notifications.
🧱 High-Level Architecture
1
2 +------------------------+
3 | External Service |
4 | (e.g., Order System) |
5 +----------+-------------+
6 |
7 [1] API / Event
8 |
9 +-----------v------------+
10 | Notification Gateway |
11 +-----------+------------+
12 |
13 [2] Validation & Enrichment
14 |
15 +-----------v------------+
16 | Notification Orchestrator |
17 +-----------+------------+
18 |
19 [3] Publish to MQ
20 |
21 +--------------------------------------+
22 | Message Queue |
23 | (Kafka / SQS / PubSub) |
24 +----+---------------+-----------------+
25 | |
26 +--------v---+ +------v--------+
27 | Email Svc | | SMS Service |
28 +--------+---+ +------^--------+
29 | |
30 | |
31 +-----------v----+ +-------v----------+
32 | Push Service | | In-App Service |
33 +----------------+ +------------------+
34
35 |
36 v
37 +-------------------+
38 | Notification DB |
39 | (Status, Logs) |
40 +-------------------+
41 |
42 v
43 +-------------------+
44 | Analytics Service |
45 +-------------------+🗄️ Data Model (Simplified)
Notification
1
2{
3 "id": "uuid",
4 "user_id": "u123",
5 "type": "ORDER_CONFIRMATION",
6 "channels": ["EMAIL", "SMS"],
7 "status": "SENT",
8 "created_at": "timestamp",
9 "updated_at": "timestamp"
10}Template
1
2{
3 "template_id": "t001",
4 "type": "ORDER_CONFIRMATION",
5 "subject": "Your order {{order_id}} is confirmed!",
6 "body": "Hi {{user_name}}, your order has been confirmed."
7}UserPreference
1
2{
3 "user_id": "u123",
4 "email_enabled": true,
5 "sms_enabled": false,
6 "dnd_start": "22:00",
7 "dnd_end": "07:00"
8}⚡ Key Design Decisions
1. Decoupling
2. Extensibility
3. Scalability
4. Retries & Failures
5. Template Rendering
6. User Preferences
📈 Sample Flow
Trigger:
Orchestrator:
Enqueue:
Channel Service:
Status Update:
Retry (if failed):
💾 Storage Design
| Data Type | Storage Option | Reason |
| ----------------- | --------------------- | ---------------------------- |
| Notification Logs | PostgreSQL / DynamoDB | Consistent writes, queryable |
| Templates | Redis + S3 | Fast access + durability |
| User Preferences | PostgreSQL / Redis | Low latency reads |
| Message Queue | Kafka / SQS | Decoupled async processing |
| Metrics | Prometheus / ELK | Observability |
🧠 APIs
| Method | Endpoint | Description |
| ------ | --------------------------- | -------------------------- |
| `POST` | `/notify` | Trigger a new notification |
| `GET` | `/notifications/{user_id}` | Get user notifications |
| `GET` | `/status/{notification_id}` | Fetch delivery status |
| `POST` | `/preferences` | Update user preferences |
| `POST` | `/template` | Create/update a template |
🚀 Scalability & Optimization
✅ Goal:
Build a modular, reliable, and scalable notification platform that delivers messages across channels, supports retries, respects user preferences, and can be easily extended to handle new types of notifications or delivery mechanisms.