System design case study C04 · Queues · Reliability

Design a Notification System

Send the right message, on the right channel, at the right time, without spamming anyone or losing the OTP someone is waiting for.

What you'll be able to explain
  • Fan out notifications across push, SMS, email and in-app channels
  • Separate priorities so OTPs never wait behind marketing
  • Respect user preferences, quiet hours and frequency caps
  • Deliver reliably through flaky third-party providers
  • Track delivery and engagement

Scope

Functional

  • Internal services send notifications: transactional (OTP, order shipped) and bulk (campaigns).
  • Channels: mobile push (FCM/APNs), SMS, email, in-app inbox.
  • Templates with localisation; user preferences and opt-outs; scheduling.

Non-functional

  • OTPs delivered to the provider in < 2 s at p99.
  • No duplicate sends for the same event; at-least-once internally, deduplicated.
  • Campaigns to 100M users complete within an hour without hurting transactional traffic.

Size

  • Transactional: 50M/day → ~600/s average, a few thousand/s peak.
  • Campaigns: 100M in an hour → ~28,000/s bursts.
  • Provider limits (SMS gateways, email providers) are often the real bottleneck.

API

POST /v1/notifications
{ "idempotency_key": "order-881-shipped",
  "user_id": 42, "template": "order_shipped", "params": {...},
  "channels": ["push","email"], "priority": "high", "send_at": null }

The architecture

SERVICEInternal servicesSERVICENotification APIvalidate, dedupeCACHEPreferences+ caps (Redis)QUEUE / LOGHigh-priorityqueueQUEUE / LOGBulk queueWORKERPush workersWORKERSMS workersWORKEREmail workersEXTERNALProvidersFCM, APNs, SMS, SESDATABASEDelivery logallowed? channel?OTP, txncampaigns
Priority-separated pipeline: validate once, then fan out per channel with independent workers.

The 30-second summary

Say it in the interview

"One API validates, deduplicates by idempotency key and applies preferences, caps and quiet hours. Work is split into priority-isolated queues, with per-channel worker pools rate-limited to each provider's quota. Delivery is at-least-once with per-channel sent markers, retries and provider failover. All events feed a delivery log for tracking."

Follow-up questions the interviewer may ask

  1. How do you avoid sending the same notification twice?
  2. How do you respect quiet hours and user preferences at scale?
  3. A provider (SMS or push) is down. What happens?
  4. How do you send a campaign to 50M users without hurting transactional notifications?

Model answers to each of these are in the book.