Interview Study Guide

Guide / System design Most asked

Design: notification system

Push, SMS, email and in-app notifications at scale: ingestion, templating, preferences, per-channel workers, provider failover, deduplication, rate limits, priorities and delivery tracking.

Created · Updated · 5 min read

Fundamentals (the design)#

1. Requirements#

Functional: send notifications over push (APNs/FCM), SMS, email and in-app; triggered by events (order shipped), campaigns (marketing blast) and OTPs; user preferences and opt-outs; templates and localisation; scheduling; delivery status and analytics. Non-functional: OTP delivered in seconds, campaigns of millions within an hour, no duplicates, never spam beyond limits, tolerate provider outages, respect quiet hours and regulations (unsubscribe, DND).

2. Estimates#

10M users, 5 notifications/user/day = 50M/day ≈ 580/s average; a campaign to 10M users in 30 min ≈ 5.5K/s; OTP and transactional peaks of a few K/s. Providers are the bottleneck (they rate-limit you), so you need queues and throttles per provider.

3. Architecture#

Producers (services, campaign tool) → Notification API → validate, dedupe, preferences, template → Kafka (topic per priority/channel)
                                                                     │
                       ┌───────────────┬─────────────────────────────┼───────────────┐
                       ▼               ▼                             ▼               ▼
                  Push workers    SMS workers                   Email workers   In-app writer
                  (FCM/APNs)   (Twilio, local providers)       (SES, SendGrid)   (DB + WebSocket)
                       │               │                             │               │
                       └──────── delivery status callbacks / webhooks → status store → analytics

Components: ingestion API (idempotency key per notification), preference service (channel opt-ins, quiet hours, frequency caps, language), template service (render with variables, localise), router (choose channels by priority and preference), per-channel queues and workers with provider adapters, scheduler for delayed sends, status tracker, and device token registry (token ↔ user, cleaned on invalid-token feedback).

4. Key design points#

  • Priority isolation: separate topics/queues and worker pools for OTP/transactional vs marketing so a campaign never delays an OTP. Weighted consumption when sharing.
  • Idempotency and dedupe: dedupe_key = hash(user, template, event_id) stored in Redis/DB with TTL; consumers are idempotent so retries never double-send.
  • Rate limiting and throttling: per user (frequency caps: max 3 marketing/day), per provider (their quota), per tenant; token buckets (Rate limiting). Campaigns are spread over time with a leaky bucket.
  • Retries: exponential backoff with jitter for transient provider errors; DLQ after N attempts; do not retry on permanent errors (invalid token, unsubscribed number); remove dead device tokens.
  • Provider failover: multiple SMS/email providers with health-based routing and circuit breakers; fallback channel (push failed → SMS for critical alerts).
  • Fan-out for campaigns: a campaign job reads the audience segment in pages, writes batches of notifications to the queue (not one giant message); workers render per-user content.
  • Scheduling and time zones: store target send time per user zone; a scheduler (time-bucketed table or delayed queue) releases due messages; quiet hours defer non-critical ones.
  • Delivery tracking: providers send callbacks (delivered, bounced, opened); update the status table; metrics on delivery rate and latency per provider; bounce and complaint handling (suppression lists) protects sender reputation.
  • Compliance: explicit opt-in, unsubscribe links, DND registries, audit logs, data retention.

5. Data model#

notifications(id, user_id, template, channel, status, dedupe_key, payload, scheduled_at, sent_at), preferences(user_id, channel, enabled, quiet_hours, freq_cap), device_tokens(user_id, platform, token, last_seen), templates(id, locale, body, version). Notification volumes suggest Cassandra/DynamoDB partitioned by user_id for history and Postgres for config.

Most asked questions#

1. How do you ensure OTPs are not delayed by marketing? Separate priority queues and worker pools, reserved provider capacity, and rate limits on campaigns.

2. How do you avoid duplicate notifications? Idempotency/dedupe keys, idempotent workers, and at-least-once delivery with dedupe on send.

3. How do you handle provider outages? Circuit breakers, multiple providers, retries with backoff, and channel fallback.

4. How do you send a campaign to 10M users? Paged audience reads, batch enqueue, throttled workers, per-provider rate limits, and progress tracking.

5. How do you respect user preferences? A preference service checked before routing, cached with invalidation, with frequency caps and quiet hours.

Senior-level questions#

1. “Push says delivered but the user never saw it.” Delivery is not display: tokens may be stale, OS may throttle, notifications may be collapsed; track open/impression events, handle token refresh, use collapse keys and priority settings.

2. “A bug sent a promo to everyone twice.” Add campaign-level dedupe and idempotency, kill switches, canary sends (1% first), rate limits per user per day enforced in the pipeline, and a rollback tool that stops queued messages.

3. “Order guarantees: ‘order shipped’ must not arrive before ‘order placed’.” Partition by user_id or order_id for ordering, include sequence numbers, and let the client or in-app UI show the newest state; strict ordering across channels is not guaranteed.

4. “Throughput to a provider is capped at 500/s but you have 5K/s.” A buffered queue and token bucket per provider, parallel providers, prioritisation (transactional first), and shedding or delaying low-priority sends.

5. “How do you keep templates consistent and safe?” Versioned templates, preview and render tests, escaping to avoid injection, fallbacks for missing variables, and locale fallback chains.

Quiz#

1. What isolates OTPs from marketing sends?

Separate priority queues and worker pools (and provider quota reservations).

2. Should you retry an "invalid device token" error?

No. It is permanent: delete the token. Retry only transient errors.

3. Why campaign fan-out in batches?

Avoids massive single messages and memory spikes, enables throttling, parallelism and resumability.

4. How do you guarantee at most one send per event?

Dedupe key checked atomically (unique constraint/SETNX) before sending, plus idempotent provider requests where supported.

5. What protects sender reputation for email?

Suppression lists for bounces and complaints, SPF/DKIM/DMARC, gradual warm-up, and rate limiting.

Finished this page?Mark it done to track your progress across the guide.
Pritam Ghosh · System design & AI engineering study notes