← Back to System Design, page 2

system-design-0037 · Medium fresher

Design a notification system that sends push, email, SMS and in-app notifications to 50 million daily users.

Accept notification requests through an API, check user preferences and deduplicate, render templates, and put one message per channel on separate queues. Channel workers call providers such as APNs, FCM, an email service and an SMS gateway, with retries, rate limits and a dead-letter queue. About 500M notifications per day means roughly 5,800 per second on average and about 29,000 at a 5x peak.

Full answer

Requirements

Functional:

  • Other services (assignments, payments, live classes) send notifications to users by push, email, SMS or in-app inbox.
  • Users can opt out per channel and per category ("marketing", "class reminders").
  • Templates with variables and multiple languages.
  • Scheduled sends ("remind 15 minutes before class") and delivery status.

Non-functional:

  • At-least-once delivery for important messages; no duplicates visible to users.
  • Time-sensitive messages (OTP codes, class starting) go out within seconds even when a marketing campaign is running.
  • Survives provider outages; scales for campaign spikes.

Capacity estimates

Assumptions: 50M DAU, 10 notifications per user per day on average, peak factor 5 (campaigns and class start times cluster), 1 KB stored per notification record, 30 days retention for the history and in-app inbox.

  • Volume: 50M x 10 = 500M per day; 500M / 86,400 = about 5,800 per second; about 29,000 per second at peak.
  • Storage: 500M x 1 KB = 500 GB per day; 30 days = 15 TB.
  • Device tokens: 50M users x 2 devices x about 200 bytes = about 20 GB.

These numbers say: queues are required to absorb peaks, and the history store should be a horizontally scaled store partitioned by user.

API

POST /v1/notifications { "idempotency_key": "class-981-reminder-user-77", "user_id": 77, "category": "class_reminder", "template": "class_starting", "params": {"class_name": "Physics 10B", "minutes": 15}, "channels": ["push", "in_app"], "priority": "high", "send_at": "2026-12-04T09:45:00Z" } -> 202 {"notification_id": "n_8f2c..."} GET /v1/users/77/inbox?cursor=... in-app list PUT /v1/users/77/preferences opt-in/out per channel and category

Data model

  • notifications (partition by user_id, sort by time): id, user_id, category, channel, status (queued, sent, delivered, failed), created_at, rendered_body.
  • preferences: user_id, category, channel, enabled, quiet hours, time zone.
  • devices: user_id, platform, push_token, last_seen.
  • templates: name, locale, version, body.

High-level design

mermaid
flowchart LR
  S[Producer services] --> API[Notification API]
  API --> V[Validate + preferences + dedup]
  V --> SCH[Scheduler for send_at]
  V --> HQ[High-priority queues]
  V --> LQ[Bulk queues]
  SCH --> HQ
  HQ --> PW[Push workers] --> APNS[APNs / FCM]
  HQ --> SW[SMS workers] --> SMS[SMS provider]
  LQ --> EW[Email workers] --> ESP[Email provider]
  PW --> DB[(Notification store)]
  EW --> DB
  SW --> DB
  PW -. failures .-> DLQ[Dead-letter queue]

Flow

  1. The API validates the request and stores the idempotency key; repeats return the original ID.
  2. It reads the user's preferences and devices (cached), drops disabled channels, respects quiet hours in the user's time zone.
  3. It renders the template and enqueues one message per channel. Future send_at goes to a scheduler (a time-bucketed table or delayed queue) that enqueues at the right time.
  4. Channel workers send through providers, record status, and retry with exponential backoff on temporary errors.
  5. Provider callbacks (delivered, bounced, token invalid) update status; invalid push tokens are deleted.

Scaling and bottlenecks

  • Separate queues per channel and priority so a 20M-email campaign cannot delay OTP SMS.
  • Provider rate limits: SMS and email providers limit sends per second; workers use a leaky bucket per provider account.
  • Provider outage: keep a second provider for SMS and email and switch on error rate.
  • Duplicates: at-least-once queues can redeliver, so workers check a per-message sent flag (or pass an idempotency key to the provider) before sending.
  • Campaign fan-out: a campaign to 10M users is expanded in batches by a separate job, not in the API request.

Trade-offs

Per-channel queues add infrastructure but isolate failures. Storing every notification enables history and debugging but costs 15 TB per month of retention; shorter retention for bulk categories saves money. Strict exactly-once delivery is not possible with external providers, so the design aims for at-least-once with deduplication.

By level

Fresher: Describe the API, preferences check, a queue, and workers that call push, email and SMS providers, with retries. A fresher should mention user opt-outs.

Mid: Estimate volume and storage, separate queues by channel and priority, design the data model and scheduling, and handle duplicates. Expect separate queues so marketing cannot delay one-time passwords.

Senior: Plan for campaign fan-out, provider failover and rate limits, multi-region delivery, observability of delivery rates, cost per channel and compliance rules such as opt-out and quiet hours. Expect provider failover and cost per channel to be discussed.

Key points

  • Queue per channel and priority to isolate failures and campaigns
  • Check preferences, quiet hours and idempotency before enqueueing
  • About 5,800 per second average and 29,000 at a 5x peak for 500M per day
  • Workers retry with backoff, respect provider limits, and use a dead-letter queue
  • Delivery is at-least-once with deduplication, not exactly-once

Common mistakes

  • Sending directly from the API request without a queue
  • One shared queue where marketing blocks OTPs
  • Ignoring user preferences and time zones
  • Not cleaning invalid push tokens

Follow-ups

  • How would you send a campaign to 10 million users without overloading providers?
  • How do you guarantee a reminder goes out 15 minutes before class?
  • How would you track whether a push notification was opened?

Tips

  • Separate time-critical and bulk traffic early in your design
  • Mention provider rate limits and failover
  • Show the idempotency key in the API

Evaluation rubric

  • Covers channels, preferences, templates and scheduling
  • Capacity math with stated assumptions
  • Queue-based design with retries and DLQ
  • Discusses duplicates, priorities and provider failures