🇮🇳
🇮🇳
Republic Day Special Offer!Get 20% OFF on all courses
Enroll Now
P
Prakalpana
📚Learn
Code Your Future
System Design⏱️ 16 min read📅 Jan 10

Design Notification System - Push, SMS, Email at Scale (Interview Guide)

AT
Amit TandonEngineering Manager at Uber
📑 Contents (19 sections)

📌The Interview Question

"Design a notification system that can send push notifications, SMS, and emails to millions of users"

📌Step 1: Requirements

Functional

  • Support multiple channels: Push, SMS, Email
  • User preferences (opt-in/opt-out per channel)
  • Template-based messages
  • Scheduling
  • Rate limiting per user
  • Non-Functional

  • High throughput (1M+ notifications/minute)
  • At-least-once delivery
  • Prioritization (OTP > Marketing)
  • Low latency for critical notifications
  • 📌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 Templates
    CREATE TABLE templates (
    id VARCHAR(50) PRIMARY KEY,
    channel VARCHAR(20),
    subject TEXT,
    body TEXT,
    variables JSON
    );
    -- User Preferences
    CREATE TABLE user_preferences (
    user_id BIGINT,
    channel VARCHAR(20),
    enabled BOOLEAN,
    PRIMARY KEY (user_id, channel)
    );
    -- Notification Log
    CREATE 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?

  • Decouple services
  • Handle traffic spikes
  • Retry failed messages
  • Scale independently
  • 📌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

  • Exponential backoff
  • Max retries: 3
  • Dead letter queue for failed
  • Fallback

  • Push failed → Try SMS
  • SMS failed → Try Email
  • 📌Step 8: Scaling Considerations

    Database

  • Sharding by user_id
  • Separate read replicas for analytics
  • Workers

  • Horizontal scaling
  • Auto-scale based on queue depth
  • Providers

  • Multiple providers per channel
  • Circuit breaker for failing providers
  • 📌Common Follow-up Questions

    Q: How to ensure no duplicate notifications?

  • Idempotency key in request
  • Dedup at worker level
  • Q: How to handle time zones?

  • Store user timezone
  • Schedule jobs consider timezone
  • Q: Analytics?

  • Track: sent, delivered, opened, clicked
  • Store in analytics DB (ClickHouse)
  • This is a favorite question at Amazon and Uber. Our course covers this with working code.

    AT

    Written by

    Amit Tandon

    Engineering Manager at Uber

    🚀 Master System Design

    Join 500+ developers

    Explore Courses →
    Chat on WhatsApp