{}DSA Atlas

Design a Notification System

A multi-channel notification platform (push, SMS, email, in-app) used by every product team — event ingestion, user preferences and quiet hours, templating and localisation, priority queues per channel, provider integrations with retries and failover, deduplication, rate limiting and digests, scheduled and bulk campaigns, delivery tracking and analytics.

Intermediate → Advanced5 interview questions

1. Requirements

Functional

  • Channels: mobile push (iOS/Android), SMS, email, in-app inbox (and web push).
  • Triggered by services (transactional) and by campaigns (bulk marketing), immediate or scheduled.
  • Per-user preferences, quiet hours, unsubscribes; templates with localisation.
  • Delivery status and analytics (sent, delivered, opened, clicked).

Non-functional

  • 1B notifications/day; spikes of 10× during campaigns or incidents.
  • Transactional p99 latency < 5 s end-to-end (OTP!).
  • At-least-once with dedup → effectively once; no lost transactional notifications.
  • Extensible: adding a channel or provider shouldn't touch producers.

2. Estimation

QuantityValue
Average rate1B/day ≈ 11.6k/s
Peak~100k/s
Status events~3 per notification → ~35k/s avg writes
Storage1 KB per notification + status → ~1 TB/day (keep 30–90 days hot)

3. API

HTTP
POST /v1/notifications
Idempotency-Key: order_8812:shipped

{
  "recipients": [{"user_id": "u_17"}],
  "type": "order_shipped",
  "priority": "high",
  "data": {"order_id": "8812", "eta": "2026-10-09"},
  "channels": ["push", "email"],          // optional override; default from type config
  "send_at": null
}
202 Accepted  {"notification_id": "n_01J…", "status": "queued"}

4. High-level design

services campaign tool scheduler notify APIvalidate · dedupe Kafka routerprefs · templatescaps · quiet hours prefs / contacts template store push queue SMS queue email queue in-app queue workers → APNs · FCM · Twilio · SES · inbox DB status store + analytics ← provider webhooks separate high/low priority topics and worker pools per channel
Producers only describe *what* happened; the platform decides how and where to notify.

5. Data model

SQL
CREATE TABLE notification (
  id              TEXT PRIMARY KEY,           -- ULID
  idempotency_key TEXT UNIQUE,
  user_id         BIGINT NOT NULL,
  type            TEXT NOT NULL,
  payload         JSONB NOT NULL,
  priority        TEXT NOT NULL,
  created_at      TIMESTAMPTZ NOT NULL
);
CREATE TABLE delivery (
  notification_id TEXT REFERENCES notification(id),
  channel         TEXT,                        -- push | sms | email | inapp
  status          TEXT,                        -- queued | sent | delivered | failed | opened
  provider        TEXT,
  attempts        INT DEFAULT 0,
  updated_at      TIMESTAMPTZ,
  PRIMARY KEY (notification_id, channel)
);
-- preferences: (user_id, category, channel) -> enabled; quiet_hours; timezone
-- devices: (user_id, device_id) -> platform, push_token, last_seen

At very high volume the delivery log moves to Cassandra/DynamoDB (write-heavy, TTL) and analytics to a columnar store.

6. Deep dives

Routing logic

Python
def route(n: Notification):
    if dedupe.seen(n.idempotency_key):
        return
    cfg = notification_types[n.type]                     # default channels, category, priority
    prefs = preferences.get(n.user_id)                   # cached
    channels = [c for c in (n.channels or cfg.channels) if prefs.allows(cfg.category, c)]
    if cfg.category == "marketing" and caps.exceeded(n.user_id, "marketing", per_day=3):
        return
    for ch in channels:
        when = quiet_hours.next_allowed(prefs, now()) if cfg.respect_quiet_hours else now()
        msg = templates.render(cfg.template[ch], locale=prefs.locale, data=n.payload)
        queues[ch][n.priority].enqueue(msg, deliver_at=when)

Provider integration

ChannelProvider facts
iOS pushAPNs over HTTP/2; device tokens change; invalid token → 410 → delete
Android pushFCM HTTP v1; collapse keys; topic messaging
SMSTwilio/Vonage; per-country regulations, sender IDs, cost per message; OTP via dedicated routes
EmailSES/SendGrid; SPF/DKIM/DMARC, IP warm-up, bounce and complaint handling, unsubscribe headers
In-appwrite to an inbox table + real-time push over WebSocket if online

Use a circuit breaker per provider and fail over (e.g., SMS via a second vendor) when error rates spike.

Scheduling and digests

  • Scheduled sends: store with send_at; a scheduler (time-bucketed table or delay queue) releases them — see job scheduler.
  • Digests: accumulate events per user/type in a window (Redis list with TTL); a timer flushes one aggregated notification.

Rate limiting

Per-user (fatigue), per-provider (contractual limits), per-tenant (fairness among internal producers). Bulk queues drain at a configured rate.

7. Trade-offs

ConcernDecision
Latency vs throughputseparate priority lanes; transactional never queues behind marketing
Exactly-onceidempotency keys + per-channel send state (effectively once)
Preferences consistencycached with short TTL + invalidation on change; legal unsubscribes applied immediately
Provider dependencemulti-provider with failover; abstraction layer per channel
Observabilityper-type funnel: requested → sent → delivered → opened

Interview questions

0 / 5 marked confident

Answer out loud first, then open the model answer. Mark a question confident only when you could explain it to an interviewer without notes.