Design a Notification System

Send push, SMS, email and in-app notifications reliably at scale with preferences, templates, priorities, retries and deduplication.

Intermediate · about 4 hours · difficulty 3/5

Learn first: Delivery Guarantees and Event-Driven Design, Idempotency, Retries and Timeouts

Every product sends notifications: OTPs, order updates, offers, reminders. At Swiggy or Flipkart scale that means crores of messages a day across channels with very different urgency.

Requirements

  • Channels: push (FCM for Android, APNs for iOS), SMS (via Indian SMS gateways, with DLT template registration), email, in-app.
  • Transactional (OTP, order status) and promotional (sale alerts) types with different priorities.
  • User preferences and opt-outs, quiet hours, templates in multiple languages.
  • Reliable delivery with retries, no duplicates, delivery tracking.

Architecture

  1. Internal services call a Notification API with event type, user and data (not raw message text).
  2. The service checks preferences, rate limits per user, renders a template, and picks channels.
  3. It enqueues jobs onto per-channel, per-priority queues (OTP queue separate from marketing queue, so a 5 crore user campaign never delays an OTP).
  4. Channel workers call third-party providers (FCM, APNs, SMS and email vendors) with timeouts, retries with backoff, and failover to a backup provider.
  5. A delivery log records status; provider webhooks update delivered or failed.

Reliability details

  • Idempotency: a notification ID per event so retries do not send the same SMS twice.
  • Dead letter queues for permanent failures; invalid device tokens get cleaned up.
  • Rate limiting per user (no one wants 20 pushes an hour) and per provider (respect vendor throughput limits).
  • Scheduling for reminders and campaigns at a chosen time, spread out to avoid traffic spikes.

Pitfalls

  • One shared queue for everything, so marketing blasts delay OTPs.
  • Sending promotional SMS without consent or DLT-registered templates (it gets blocked in India).
  • No dedup, so a retry storm sends five copies of "your order is delivered".

You are ready to move on when you can draw this pipeline, explain how an OTP stays fast during a mega campaign, and describe how duplicates are prevented end to end.

Key concepts

  • Push, SMS, email and in-app channels
  • User preferences and opt-outs
  • Templates and localisation
  • Priority queues per channel
  • Retries, DLQs and provider failover
  • Deduplication
  • Scheduled campaigns
  • DLT rules for SMS in India

Mini project

Write a design doc and build a prototype with a notification API, a preferences table, two priority queues and email plus mock-SMS workers with retries and dedup by notification ID. Fire a 1 lakh message campaign and show OTP latency stays low.

Check yourself

How would you guarantee that a marketing campaign to 5 crore users never delays an OTP by more than a few seconds?

Free resources