Skip to main content
02

Design a notification system (push, email, SMS)

MediumMessage queueRetriesPushFan-out

Design a notification system that sends push notifications, emails and SMS on behalf of many internal services: order updates, security alerts, marketing campaigns and reminders.

A typical framing: "Any team should be able to send a notification with one API call. Users choose which notifications they get on which channel. We send about 50 million notifications a day, with campaign spikes to millions within minutes. Critical ones like password resets must arrive fast; nobody should get the same notification twice."

TL;DR

Put a notification service between producers and the channel providers (APNs, FCM, an email provider like SES or SendGrid, an SMS provider like Twilio). It validates the request, applies user preferences, rate limits and quiet hours, renders templates, and enqueues one message per channel. Separate queues per channel and priority keep a marketing blast from delaying a password reset. Channel workers call the providers with retries and exponential backoff, and a dead-letter queue catches what keeps failing.

Delivery is at least once, so make sends idempotent with a notification id (dedupe before calling the provider). Track each notification's status (queued, sent, delivered, opened, failed) from provider callbacks. Big campaigns are fanned out in batches by a separate pipeline, throttled to provider limits.

1. Requirements and estimates

Functional

  • Send to a user (or a segment) on push, email, SMS and in-app.
  • Templates with localization and variables.
  • User preferences per category and channel, unsubscribe, quiet hours.
  • Scheduling (send at a time) and status tracking.

Non-functional

  • Critical notifications delivered within seconds; marketing can be slower.
  • No duplicates, no lost notifications.
  • Scales to campaign spikes; one failing provider doesn't block other channels.

Estimates

  • 50M per day ≈ 600 per second on average; campaigns push this to tens of thousands per second.
  • Status records: 50M × ~500 bytes ≈ 25 GB per day, kept for 90 days ≈ 2 TB.

2. API

http
POST /v1/notifications
Idempotency-Key: order-981-shipped
{
  "userId": "u_42",
  "category": "order_updates",
  "template": "order_shipped",
  "data": { "orderId": "981", "eta": "2026-12-01" },
  "channels": ["push", "email"],
  "priority": "high",
  "sendAt": null
}
-> 202 { "notificationId": "ntf_7" }

GET  /v1/notifications/{id}           -> status per channel
POST /v1/campaigns                    { segmentId, template, sendAt }
PUT  /v1/users/{id}/preferences       { "marketing": { "email": false } }

The API returns 202 Accepted: delivery is asynchronous.

3. Data model

text
user_preferences   (user_id, category, channel, enabled, quiet_hours, timezone)
devices            (user_id, device_token, platform, last_seen)   -- push tokens
templates          (name, channel, locale, version, subject, body)
notifications      (id, user_id, category, template, data, priority, created_at)
deliveries         (notification_id, channel, status, provider_id, attempts, updated_at)

4. High-level architecture

Loading diagram...
  • Notification API: validates, dedupes by idempotency key, checks preferences, renders, and enqueues per channel.
  • Queues (Kafka, SQS, RabbitMQ) per channel and priority, so slow email doesn't hold up push.
  • Channel workers: stateless consumers that call providers, respecting each provider's rate limits.
  • Status store: updated by workers and by provider callbacks (delivered, bounced, opened).

5. Deep dives and scaling

Reliability and retries

  • Workers acknowledge a queue message only after the provider accepted it (at-least-once).
  • Transient errors (timeouts, 5xx, 429): retry with exponential backoff and jitter. Permanent errors (invalid token, unsubscribed address): don't retry; clean up the token or address.
  • After N attempts, move to a dead-letter queue for inspection and replay.
  • Fallback: if push fails for a critical alert, fall back to SMS.

Avoiding duplicates

Retries mean a worker might send, crash before acking, and send again. Before calling the provider, record (notificationId, channel) as "sending" with a conditional insert; skip if it already exists as sent. Pass the notification id to providers that accept an idempotency key.

Priorities and fairness

Separate queues by priority, with more workers on the high-priority ones. Inside the bulk queues, rate-limit per producer so one team's campaign can't starve everyone else.

Campaigns

A segment of 20M users isn't one API call. The campaign scheduler pages through the segment and enqueues batches, throttled to what providers allow (email providers and SMS carriers have sending limits). Spread sends over time and respect each user's timezone and quiet hours.

User experience rules

  • Preferences are checked at send time, not just when enqueued (the user may have unsubscribed in between).
  • Rate limit per user (e.g. at most 3 marketing pushes a day) and collapse similar notifications ("5 new comments" instead of five pushes).
  • Emails need unsubscribe links and must follow anti-spam laws; SMS needs opt-in.

Observability

Track queue lag, send rate, failure rate per provider, and delivery and open rates per template. Alert when a provider's error rate jumps and switch to a backup provider.

Common follow-ups

  • "How do you schedule a notification for next Tuesday at 9:00 in each user's timezone?" Store scheduled sends in a table indexed by send time; a scheduler polls due rows (or uses delay queues) and enqueues them, using FOR UPDATE SKIP LOCKED so several schedulers don't pick the same rows.
  • "How do in-app notifications differ?" They're stored in a per-user inbox table and pushed live over WebSocket or SSE when the user is online; unread counts come from the table.
  • "What if APNs is down for an hour?" Push queues grow but other channels keep working. Workers back off, and when APNs returns, old notifications past their usefulness (e.g. "your driver is arriving") are dropped using a per-notification TTL.

What interviewers look for

  • A central service that applies preferences, templates and rate limits before sending.
  • Queues per channel and priority, and stateless workers.
  • Retries with backoff, a dead-letter queue, and the difference between transient and permanent errors.
  • Idempotency to avoid duplicates under at-least-once delivery.
  • Handling campaign fan-out, provider limits, timezones and status tracking.

Was this helpful?

Related questions