📌The Interview Question
"Design a notification system that can send push notifications, SMS, and emails to millions of users"
📌Step 1: Requirements
Functional
Non-Functional
📌Step 2: High-Level Design
System Architecture
Live
Service A
Service B
Service C
Notification Service
Message Queue
Kafka/RabbitMQ
Workers
Push / SMS / Email APIs
⚡ High Availability🔄 Auto-scaling🛡️ Fault Tolerant
📌Step 3: API Design
POST /api/v1/notifications{ "user_id": "user123", "template_id": "order_confirmed", "channels": ["push", "email"], "data": { "order_id": "ORD456", "amount": "₹1,500" }, "priority": "high", "schedule_at": null // null = immediate}📌Step 4: Database Schema
-- Notification TemplatesCREATE TABLE templates ( id VARCHAR(50) PRIMARY KEY, channel VARCHAR(20), subject TEXT, body TEXT, variables JSON);-- User PreferencesCREATE TABLE user_preferences ( user_id BIGINT, channel VARCHAR(20), enabled BOOLEAN, PRIMARY KEY (user_id, channel));-- Notification LogCREATE TABLE notifications ( id BIGINT PRIMARY KEY, user_id BIGINT, channel VARCHAR(20), status VARCHAR(20), sent_at TIMESTAMP, error TEXT);📌Step 5: Message Queue Design
Priority Queues
System Architecture
Live
High Priority Queue
OTP, Security
Medium Priority Queue
Orders
Low Priority Queue
Marketing
⚡ High Availability🔄 Auto-scaling🛡️ Fault Tolerant
Why Kafka/RabbitMQ?
📌Step 6: Worker Design
public class NotificationWorker { public void process(NotificationMessage msg) { // 1. Fetch user preferences UserPrefs prefs = prefsService.get(msg.getUserId()); // 2. Check if channel enabled if (!prefs.isEnabled(msg.getChannel())) { return; // Skip } // 3. Rate limit check if (rateLimiter.isLimited(msg.getUserId())) { requeue(msg); // Try later return; } // 4. Render template String content = templateEngine.render( msg.getTemplateId(), msg.getData() ); // 5. Send via provider ProviderResponse resp = provider.send(msg.getChannel(), content); // 6. Log result logService.save(msg, resp); }}📌Step 7: Handling Failures
Retry Strategy
Fallback
📌Step 8: Scaling Considerations
Database
Workers
Providers
📌Common Follow-up Questions
Q: How to ensure no duplicate notifications?
Q: How to handle time zones?
Q: Analytics?
This is a favorite question at Amazon and Uber. Our course covers this with working code.