Course contents

17. Real-World System Design Lesson 5 of 20

Notification Service

Design a notification platform: accept fast, fan out to per-channel queues, apply preferences, contain a provider outage, retry with backoff and DLQs.

20 minAdvanced9 steps
Loading the interactive simulation…
Loading the knowledge check…

Summary

  • Accept and answer 202; never call a provider on the caller’s request path.
  • A router applies preferences and fans out to durable per-channel queues, each with its own sender pool.
  • Per-channel queues and pools are bulkheads: one provider’s outage stays in its lane.
  • Retries need backoff with jitter and a limit; what still fails goes to a DLQ that is alerted on and replayed.
  • Urgent and bulk traffic get separate queues; bulk is paced to provider limits.
  • Delivery is at least once, so senders deduplicate by idempotency key.
Deep diveHow it works, trade-offs, failure modes, misconceptions and the interview angle.

What it is

A notification platform takes requests such as "tell user 42 that order 981 has shipped" from many internal services and delivers them over push, email and SMS through external providers. It decides which channels to use for each user, renders the message, sends it, retries failures and records what happened.

This lesson builds the delivery pipeline in the 3D scene and runs its hard parts in the simulation: decoupling, per-channel fan-out, a provider outage, retries and dead letters, and a campaign flood. The full interview version, with API, data model, deduplication and capacity estimates, is at /system-design/interviews/notification-service. The building blocks are covered in Message Queues, Publish/Subscribe and Dead Letter Queues.

Why it exists

Every product team needs notifications, and each one built separately duplicates provider integrations, preference handling, retries and compliance (unsubscribe links, quiet hours). A shared platform does it once. Its hard requirements come from the mix: login codes must arrive within seconds, campaigns produce bursts tens of times the average, and providers are slow, rate limited and sometimes down.

How it works

Estimates. The interview assumes about 200 million deliveries a day:

Quantity Arithmetic Result
Average 200M ÷ 86,400 s ≈ 2,300 /s
One campaign 50M users ÷ 3,600 s ≈ 14,000 /s
SMS average 10M ÷ 86,400 s ≈ 115 /s (provider contract e.g. 1,000 /s)

The design is driven by bursts and provider limits, not the average.

Accept, then deliver. The API authenticates the calling service, checks the idempotency key, stores the notification and answers 202 Accepted. It never calls a provider. In the simulation's first step, a synchronous design collapses when the email provider slows eight times: the API's workers all wait on it.

Route and fan out. A router consumes accepted notifications, loads the user's preferences (cached), the category's channel policy, devices and suppressions, and decides channels and timing. Quiet hours or a future send_after go to a delay queue or scheduler. For each (channel, address) it writes a delivery record and publishes a message onto a per-channel, per-priority queue: push.transactional, email.bulk, and so on.

Send. Each queue has its own sender pool. A sender claims the delivery, renders the template, takes a token from the provider's rate limiter, calls the provider and records the result. Provider callbacks (delivered, bounced, invalid token) update status and suppressions.

Isolation. Because SMS has its own queue and senders, an SMS provider outage fills only the SMS queue. In the simulation, push and email keep delivering about 40 messages per second each while SMS stalls. With one shared pool, failing SMS sends would hold workers that email needs. Where a second provider exists for a channel, senders fail over to it.

Retries, backoff and dead letters. Transient failures are retried with exponential backoff and jitter, for a bounded number of attempts; then the message goes to a dead letter queue. The DLQ is alerted on and replayed after the incident, skipping messages that have expired (a login code is useless after a few minutes). Permanent failures (invalid number, hard bounce) are not retried but recorded as suppressions.

Priority and pacing. A campaign must never delay a login code. Transactional and bulk traffic get separate queues and sender pools, and the campaign fan-out job publishes at a configured rate that the provider contract allows. In the simulation, a campaign on the shared email queue grows it by more than a hundred messages a second; on its own paced queue, the transactional queue stays empty.

Delivery semantics. Queues deliver at least once: a sender that crashes after the provider accepted a message but before acknowledging it will send it again. Senders deduplicate with an idempotency key per delivery (for example a conditional status update or a dedup store with a 24-hour TTL), so a retry rarely becomes a second message.

When to use it

When several teams send notifications, when more than one channel is involved, or when volume and provider limits require queuing and pacing. A single service sending a few emails can call a provider SDK through its own queue without a platform.

When not to

  • Very low volume, one channel: a background job with a retry is enough.
  • Real-time in-app updates to connected clients belong on a WebSocket or SSE channel, not a store-and-forward pipeline (the platform can feed it, though).
  • Messages that must be delivered exactly once in a legal sense (payment confirmations of record) still need a durable record in the owning system; a notification is a courtesy copy.

Trade-offs

Choice You gain You pay
Accept-then-queue (202) Callers isolated from providers; bursts absorbed Delivery is asynchronous; status must be queried or called back
Per-channel, per-priority queues Outages and campaigns contained More queues, pools and dashboards
At-least-once with idempotency keys No lost messages Dedup store and conditional updates on the hot path
Retries with backoff and a limit Rides out transient failures without hammering providers Delivery can be minutes late during incidents
Pacing campaigns Stays within provider contracts; protects reputation Campaigns take longer
Second provider per channel Survives a provider outage Two integrations, templates and cost models to maintain

Alternatives

  • Managed notification services (cloud push/email/SMS services) instead of direct provider integrations: less to run, less control over routing and failover.
  • A log-based backbone (partitioned event stream) instead of queues for the ingest stage: replayable and ordered per user, but per-message retry and delay are harder.
  • Per-team integrations: no shared platform, maximum autonomy, duplicated effort and inconsistent user experience.

Failure modes

  • Provider outage (simulated): the channel's queue grows. Contain it per channel, retry with backoff, fail over to a second provider where possible, and expire messages that are no longer useful.
  • Retry storm: immediate, unbounded retries consume all sender capacity and hit the provider when it recovers. In the simulation, each failed attempt holding a sender for a full lease cut SMS throughput to 16 attempts per second.
  • Campaign flood (simulated): bulk traffic in a shared FIFO queue delays urgent messages.
  • Duplicates: a crash between provider acceptance and ack resends; idempotency keys prevent most visible duplicates.
  • Silent DLQ growth: dead letters nobody watches are lost notifications. Alert on DLQ depth and age.
  • Preference bugs: sending to users who opted out is a legal and trust problem. Treat preference checks as part of the critical path and test them.

In production

Monitor queue depth and the age of the oldest message per queue (age is what users feel), send success rate per provider, DLQ depth, and end-to-end time from accept to provider acceptance for transactional traffic. Autoscale senders on queue age, within provider limits. Keep templates versioned and owned by the calling teams. Honour unsubscribe and quiet hours in the router, not in the senders. Rate-limit callers per service so one team cannot flood the platform (Rate Limiter).

Common misconceptions

  • "A queue makes delivery reliable on its own." Only with acks, bounded retries, a watched DLQ and idempotent senders.
  • "Retrying faster recovers faster." Fast unbounded retries burn capacity and can extend a provider outage.
  • "One big queue with many workers is simplest." It is, until an SMS outage or a campaign stalls everything behind it.
  • "Exactly-once delivery is achievable." Across an external provider, at-least-once plus deduplication is the realistic guarantee.

Interview angle

Estimate average and campaign rates, then draw: API (202 + idempotency), router with preferences, per-channel and per-priority queues, sender pools with provider rate limiters, callbacks and status. Expect follow-ups on provider outages and failover, retries and DLQs, campaigns delaying login codes, deduplication, quiet hours across time zones, and how you would add a new channel. Work the full problem at /system-design/interviews/notification-service.

Model assumptions

The simulation is a simplified model, not a benchmark. Product services send 40 notifications per second (Poisson). The router is a topic that copies every notification to all three channels; per-user preference filtering is a scripted illustration. Push and email senders have 8 workers (about 50 ms and 100 ms per send), SMS senders 16 workers (about 50 ms), bulk email senders 8 workers (about 100 ms); service times are lognormal. Providers are scenery: an outage is modelled as the sender failing every send. A failed send is not acknowledged; the message stays leased until the queue's visibility timeout (1 s, then 120 ms from the backoff step on) and is delivered again, with a fixed delay. Exponential backoff is not modelled by the engine and is shown as a scripted walk-through for one message. The dead letter queue takes messages after 3 deliveries; replay is described, not simulated. In the first step the email provider is simulated as a server (32 workers, ~150 ms) that slows eight times. Numbers show behaviour and orders of magnitude only.

The lesson as textEvery step of the simulation, written out.
  1. 1. Calling the provider inside the request

    Product services (Orders, Security, Marketing) call the Notification API about 40 times per second. The simplest design sends each email right away and answers when the provider has accepted it.

    That ties every caller to the slowest party in the chain. One second in, the email provider slows to eight times its usual response time. The API’s workers all wait on it, its queue fills, and callers start to see timeouts and rejections, even though nothing is wrong with our own code.

    The interview sizes the real thing at about 200 million deliveries a day (≈ 2,300 per second on average, ~20,000 per second during a campaign); see /system-design/interviews/notification-service.

    Scene: Product services call the Notification API, which calls the email provider before answering. The provider slows down eight times; the API fills up waiting for it and callers see timeouts and rejections.

    Key idea: Never put an external provider on the caller’s request path: its latency and outages become yours.

  2. 2. Accept, then fan out to one queue per channel

    Now the API only stores the notification and answers 202 Accepted in a few milliseconds. A router copies it onto one durable queue per channel, push, email and SMS, and each channel has its own pool of senders that talk to that channel’s provider.

    Every notification produces three channel messages here, about 40 per second on each queue. The senders keep up easily, the queues stay nearly empty, and the callers’ latency no longer depends on any provider.

    Scene: The API hands each notification to a router that copies it onto a push, an email and an SMS queue. Each queue has its own sender pool connected to its provider. Queues stay nearly empty and callers get fast answers.

    Key idea: Accept fast, deliver asynchronously: durable per-channel queues sit between callers and providers.

  3. 3. The router decides channels per user

    Not every notification goes everywhere. Before fanning out, the router reads the user’s preferences (cached): opt-outs per category and channel, quiet hours in the user’s time zone, devices and suppressions.

    In the scripted walk-through this user allows push and email but opted out of SMS, so the router publishes two channel messages, not three. A message that falls into quiet hours would go to a delay queue instead of being dropped. (The simulated traffic in the background still copies everything to all three channels: think of it as users who allowed every channel.)

    Scene: Scripted: the router receives one notification, reads the user’s preferences, and publishes it only to the push and email queues because the user opted out of SMS.

    Key idea: Fan-out is a decision, not a broadcast: preferences, quiet hours and suppressions are applied before any channel queue.

  4. 4. The SMS provider goes down

    One second in, the SMS provider starts failing every request. A failed send is not acknowledged, so the message stays leased to its sender until the one-second visibility timeout runs out, and is then handed out again, forever. With every attempt holding a sender for a full second, the SMS senders manage only about 16 attempts per second, fewer than the 40 new SMS messages arriving, so the SMS queue grows steadily.

    Push and email do not notice. They have their own queues and their own senders, so they keep delivering about 40 messages per second each. That isolation is the point of one queue and one sender pool per channel (a bulkhead): one provider’s outage stays in its lane.

    Scene: The SMS provider fails every send. SMS messages are redelivered after each one-second lease, the SMS queue grows steadily, and push and email keep delivering normally.

    Key idea: Separate queues and worker pools per channel contain a provider outage to that channel.

  5. 5. Retry with backoff, then park it

    Retrying every second forever wastes sender capacity and hammers a provider that is already down. Two fixes:

    Exponential backoff with jitter: wait longer after each failure (here 200, 400, 800 ms, shown for one message as a scripted walk-through), randomised so retries do not arrive in waves. A delivery limit: after a few attempts the message moves to a dead letter queue for inspection and replay.

    In the simulation a failed send now hands the message back after a short lease (120 ms instead of a second, so failures stop tying up senders), and each SMS gets three deliveries before it is dead-lettered. The engine redelivers after that fixed lease rather than a growing backoff. The SMS queue stays small; the DLQ collects the messages instead.

    Scene: Scripted: one SMS is attempted four times with growing waits, then moved to the dead letter queue. In the simulation SMS messages are dead-lettered after three deliveries, so the SMS queue stays small while the DLQ grows.

    Key idea: Bound retries in count and spread them in time; what still fails goes to a DLQ, not back to the front of the line.

  6. 6. The provider recovers

    Two seconds in, the SMS provider works again. Messages still within their retry budget go out on their next delivery, and new SMS messages are delivered and acknowledged normally, about 40 per second.

    The dead letter queue stops growing but keeps what it has. Those messages were accepted with a 202, so they must not be silently lost: after the outage an operator (or an automatic job) replays them, skipping any that have expired, like a login code that is useless after five minutes. In production a sender would also fail over to a second SMS provider where one exists, instead of waiting.

    Scene: The SMS provider recovers. SMS deliveries succeed again at about 40 per second, and the dead letter queue stops growing and waits for replay.

    Key idea: A DLQ is a to-do list, not a bin: alert on it, then replay or expire its messages deliberately.

  7. 7. A marketing campaign floods the email queue

    Marketing starts a campaign and publishes 150 emails per second straight onto the email queue. The email senders manage about 80 per second, so the queue grows by more than a hundred messages every second.

    The problem is not the campaign, which may take an hour. It is that a password-reset email or a login code now waits behind thousands of newsletters in the same first-in-first-out queue.

    Scene: A campaign job publishes 150 emails per second onto the email queue, which the email senders cannot drain; the queue grows by more than a hundred messages a second and transactional emails wait behind it.

    Key idea: Bulk and urgent traffic in one FIFO queue means urgent messages wait behind the bulk.

  8. 8. Separate queues for urgent and bulk

    Bulk mail now goes to its own queue with its own senders, and the campaign job publishes at a configured rate (70 per second) that the bulk senders and the provider’s contract allow.

    The transactional email queue is back to nearly empty: a login code is sent within milliseconds of being accepted. The bulk queue holds a small backlog and the campaign simply takes as long as it takes. The interview design does this for every channel: push.transactional, push.bulk, and so on.

    Scene: The campaign now publishes 70 emails per second to a separate bulk queue with its own senders. The transactional email queue stays nearly empty; the bulk queue holds a small backlog.

    Key idea: Give urgent traffic its own queue and workers, and pace bulk traffic to what the provider allows.

  9. 9. The pipeline, and what it trades

    The design: accept and answer 202; a router applies preferences and fans out to per-channel, per-priority queues; each queue has its own senders, retry budget with backoff, and dead letter queue; providers are isolated from each other and from callers.

    What it trades: delivery is at least once (a sender that crashes after the provider accepted a message but before acking it will send it again), so senders deduplicate by an idempotency key; more queues and pools to operate; and delivery is no longer instant, only fast when nothing is backed up, so monitor queue age, not just depth.

    Scene: The full pipeline runs: the API, router and preferences; push, transactional email, bulk email and SMS queues with their own senders; the SMS dead letter queue. Everything is delivering and the transactional queues are nearly empty.

    Key idea: A notification platform is a pipeline of durable queues: isolate channels and priorities, bound retries, and make duplicates harmless.