StackMonkey

How to design a notification system at scale

Architecture, priority queues, provider limits, retries with jitter and delivery guarantees for a notification system sending 500 million messages a day.

By StackMonkey, . 16 minute read.

Architecture diagram of a notification system: an event API with idempotency keys, a deduplication and preference filter, separate P0, P1 and P2 queues, channel workers with timeouts and circuit breakers, push, email and SMS providers, a retry queue with backoff and jitter, and a dead-letter queue

A notification system at scale is a pipeline of queues in front of providers you do not control. An event comes in with an idempotency key, is checked against the user's preferences, goes onto a queue for its priority and channel, and a worker hands it to Apple, Google, an email service or an SMS gateway. Each provider has its own rate limits, payload limits and failure modes, so most of the design is about isolating traffic, retrying the right failures with backoff, and accepting that delivery is at least once. "Exactly once" is something you approximate with deduplication, not something any queue gives you.

Key takeaways

  • Give each priority and channel its own queue and worker pool. A one-time password stuck behind a 12-million-message marketing backlog waits minutes, not seconds.
  • Size against provider limits, not just your own throughput. FCM's default quota is 600,000 messages a minute (10,000 a second), and a US short code sends 100 SMS a second.
  • Retry only failures that can succeed later (429, 5xx, timeouts), with exponential backoff, full jitter and a cap on attempts. Delete device tokens that come back as unregistered.
  • Queues and providers deliver at least once. Make sends idempotent with a key per notification and channel, so retries do not reach the user twice.

What does a notification system have to do?

A notification system takes events from other services ("order shipped", "login code requested", "weekly digest ready") and turns each one into zero or more messages on push, email and SMS, for the right user, at the right time, without duplicates. The hard requirements are usually these:

  • Latency by priority. A login code (OTP) is useless after a minute. A receipt can take 30 seconds. A marketing email can take hours.
  • Respect for the user. Opt-outs, quiet hours and frequency caps are checked before anything is sent.
  • No duplicates the user can see, even though every component in the path can retry.
  • Survive provider trouble. Apple, Google, the email provider and the SMS gateway all throttle, slow down and fail independently.

The numbers set the shape. The notification system template models 500 million notifications a day with a 50,000 a second peak. The average works out like this:

Channel Share Per day Average per second
Mobile push 60% 300M 3,472
Email 30% 150M 1,736
SMS 10% 50M 579
Total 100% 500M 5,787

The peak is 50,000 ÷ 5,787 ≈ 8.6 times the average. That gap is the reason for most of what follows: marketing campaigns arrive as bursts, and the system has to absorb them without delaying the messages that matter.

What is the architecture of a notification system?

The pipeline has six parts, each of which can scale and fail on its own. The diagram at the top of this article shows how the first five connect.

  1. Ingestion API. Authenticates the calling service, validates the template and its variables, and requires an idempotency key. It writes the event to a queue and returns quickly; it never calls a provider directly.
  2. Deduplication and preference filter. Drops events whose key it has already seen, looks up the user's channels, opt-outs, quiet hours and frequency caps, and decides which channels to use.
  3. Queues per priority and channel. P0 (OTP, fraud alerts), P1 (transactional) and P2 (marketing), split again by channel, so one cannot block another.
  4. Channel workers. Render the message, attach the device token, email address or phone number, and call the provider with tight timeouts and a circuit breaker.
  5. Retry queue and dead-letter queue. Retryable failures go back with a delay; messages that run out of attempts go to a dead-letter queue (DLQ) with an alarm on it.
  6. Delivery log. Records every attempt and its result, receives provider callbacks (delivered, bounced, unsubscribed) and feeds them back into the preference store.

Large production systems look similar. LinkedIn's Air Traffic Controller, which processes "over a billion requests per day", sits between the services that want to notify members and the channels; it rate-limits "upstream applications to prevent them from accidentally spamming members", holds back notifications while a member is likely asleep, and groups several reminders "together and send them in one email" (LinkedIn Engineering, 2018). Uber's real-time push platform splits messages into high, medium and low priority, gives each message a time to live ranging "from a few seconds to up to 30 minutes", and deduplicates messages generated "multiple times through various triggers or retries" (Uber Engineering, "Uber's Real-Time Push Platform", 2020).

Where the event comes from matters too. If a service writes an order to its database and then publishes "order shipped" in a separate step, a crash between the two loses the notification or sends one for an order that was rolled back. Writing the event to an outbox table in the same transaction, and publishing from there, closes that gap; the payment system template walks through the transactional outbox pattern.

Why does each priority need its own queue?

Because a queue is first in, first out. If OTPs share a queue with a marketing campaign, every OTP waits for every campaign message ahead of it, and no amount of worker tuning changes the order.

Take a push campaign that enqueues 50,000 messages a second, the template's whole peak rate, for 10 minutes, while the push workers drain 30,000 a second (both the drain rate and the duration are assumptions for this example). The backlog grows by 20,000 messages a second and reaches 20,000 × 600 = 12 million messages. A login code that arrives at that moment waits 12,000,000 ÷ 30,000 = 400 seconds, nearly 7 minutes, for a message whose target is under 2 seconds. The backlog takes another 400 seconds to clear, so for about 17 minutes the OTP path is broken, even though nothing has failed.

0 s100 s200 s300 s400 s0 min5 min10 min15 minTime since the campaign startedCampaign: 50,000/s in, 30,000/s out for 10 min400 s waitShared queueOwn P0 queue: under 2 s
How long a login code waits when it shares a queue with a campaign that enqueues 50,000 messages a second for 10 minutes against 30,000 a second of drain. The 50,000/s rate is the template's peak; the 30,000/s drain and 10-minute duration are assumed for illustration. Wait = backlog ÷ drain rate.

With a separate P0 queue and its own workers, the OTP's wait depends only on OTP traffic, which is small and steady. The same reasoning splits queues by channel: if the SMS gateway slows down, push and email should keep moving. The cost is more queues and worker pools to run, and capacity that sits idle when its priority is quiet. That is a price worth paying for P0; P1 and P2 can share capacity as long as P1 is served first.

The same backlog arithmetic applies to every queue in the system, and what happens when a message queue fills up covers what brokers do when one hits its limit. Workers are not the only bottleneck: the busiest component in the path is, and for notifications that is often the provider's quota (how to find the bottleneck in a system design shows the utilisation arithmetic).

How do push, email and SMS providers limit you?

Each provider throttles, caps payload size and expires messages in its own way, and your send rate has to fit inside those limits, not just inside your own capacity.

Provider Limit Source
Firebase Cloud Messaging 600,000 messages a minute per project by default; 4,096-byte payload; 240 messages a minute and 5,000 an hour to one Android device; TTL up to 28 days FCM quotas, error codes, message lifespan
Apple Push Notification service 4 KB payload (5 KB for VoIP); apns-collapse-id up to 64 bytes; stored for up to 30 days when apns-expiration is non-zero Sending notification requests to APNs
Twilio SMS 1 message a second per US long code, 100 per short code; queued for 10 hours by default Twilio scaling and queueing
Email (SMTP) Retry interval at least 30 minutes, give up after at least 4 to 5 days RFC 5321, section 4.5.4.1
Gmail bulk senders Over 5,000 messages a day: authentication (SPF, DKIM, DMARC), one-click unsubscribe, spam rate below 0.10% and never 0.30% Google, 2023; Gmail Help, Email sender guidelines

Two of these change the design at this scale:

  • FCM's default quota is 10,000 messages a second. If push is 60% of the 50,000 a second peak (30,000 a second) and Android receives half of it, that is 15,000 a second, above the default. Either request more quota or pace campaigns so the total stays under it. Google's own figure is that the default "covers over 99% of FCM developers"; a system whose peak is this high is among the few that have to plan for it.
  • SMS needs many sender numbers. At an average of 579 SMS a second, a single 100-a-second short code is not enough, and 1-a-second US long codes are out of the question for volume. The SMS worker has to spread traffic across a pool of numbers and track each one's rate.

Push providers also hold messages for offline devices and may merge them. FCM replaces an undelivered collapsible message with a newer one, and allows at most four collapse keys per token at a time (FCM collapsible messages). APNs merges notifications that share an apns-collapse-id and, for an offline device, "may coalesce notifications for the same bundle ID" (Apple). Use this deliberately: a "3 new messages" badge should collapse, and an OTP should carry a short TTL so a stale code is never shown.

What should you do with dead device tokens?

Delete them. When FCM returns UNREGISTERED (HTTP 404), Google's guidance is to "remove this registration token from the app server and stop using it", and when APNs returns 410 the token is inactive and "there is no need to send further pushes" to it (FCM error codes, Apple). FCM treats a token as stale if its app has not connected for a month, and expires Android tokens after 270 days of inactivity (FCM token management). Without cleanup, a growing share of every campaign is spent on devices that no longer exist.

How should a notification system retry failed sends?

Retry only what can succeed later, wait longer each time with randomness added, and stop after a fixed number of attempts. Everything else is a permanent failure that should be recorded, not repeated.

Provider response Meaning Action
429 Too Many Requests Throttled Honour Retry-After; for FCM, wait at least 60 seconds if it is absent
5xx, connection error, timeout Provider trouble Retry with exponential backoff and jitter
404 / 410 unregistered token Device gone Delete the token, do not retry
400 invalid payload Bug in the message Do not retry; send to the DLQ and alert

Amazon SNS draws the same line for its own push, SMS and email deliveries: it treats all 5xx and 429 responses as retryable and everything else as permanent, makes up to 50 attempts over 6 hours for those endpoints, applies jitter, and discards the message at the end unless a dead-letter queue is attached (Amazon SNS delivery retries).

Backoff with full jitter. For retry n (n = 0 for the first retry), wait a random time between 0 and min(cap, base × 2ⁿ). With a 2-second base and a 10-minute cap, the windows are 0 to 2 s, 0 to 4 s, 0 to 8 s and so on until they reach 10 minutes. The randomness matters: after a provider outage, thousands of workers fail at the same moment, and without jitter they all retry at the same moment too. In AWS's simulation, "the no-jitter exponential backoff approach is the clear loser", and full jitter cut the number of calls by more than half with 100 competing clients (AWS Architecture Blog). FCM gives the same advice: "To avoid retry amplification, implement exponential back-off with jittering" (Firebase).

Retry in one place. If the API, the worker and the HTTP client each retry three times, one failed send becomes 27 calls. Amazon's guidance is to "retry at a single point in the stack", and it notes that with five layers each retrying three times, "the load on the database will increase 243x" (Amazon Builders' Library). In a notification system that point is the retry queue: the worker makes one call, and on a retryable failure re-enqueues the message with a delay.

Give each priority its own retry policy. An OTP is worth a few fast retries over the next 30 seconds and nothing after that; a receipt can retry for hours; email, by RFC 5321, keeps trying for days.

Why do timeouts matter more than retries?

Because a provider that hangs does more damage than one that fails. A worker thread waiting on a stuck connection is a thread not sending anything else.

The template's example SMS worker pool has 100 threads, and a healthy send takes 200 ms, so the pool sends 100 ÷ 0.2 = 500 messages a second (Little's Law: throughput = concurrency ÷ time per request). That is below the 579 a second SMS average, so a real fleet runs several such pools: at least two for the average and about ten for the 5,000 a second SMS share of the peak. Take one of them. If the gateway stops answering and every call waits for a 10-second timeout, the same pool sends 100 ÷ 10 = 10 a second. Meanwhile messages keep arriving, and the backlog grows by nearly the full arrival rate.

Healthy, 200 ms per send500/sGateway hung, 1 s timeout100/sGateway hung, 2.5 s timeout40/sGateway hung, 10 s timeout10/sSMS sent per second by one pool of 100 threads
Throughput = threads ÷ time per call. When the provider hangs, the timeout sets the time per call, so the timeout, not the worker count, sets how many messages still get out.

Two fixes work together. Short timeouts (the template uses 1 second to connect and 2.5 seconds to read) limit how long a thread can be held. A circuit breaker goes further: when the error rate passes a threshold, it stops calling the provider for a while, fails fast, and lets the retry queue hold the messages or routes them to a second provider. The breaker turns "every thread blocked for 10 seconds" into "no calls for 30 seconds, then a test call".

What delivery guarantee can a notification system give?

At least once, made to look like exactly once with idempotency. No queue or provider will promise more, and the reason is structural rather than a missing feature.

  • Amazon SQS standard queues deliver at least once and say plainly: "you might get that message copy again… Design your applications to be idempotent" (SQS). FIFO queues remove duplicate sends only within a 5-minute deduplication interval (SQS FIFO).
  • Kafka "guarantees at-least-once delivery by default", and its exactly-once support covers Kafka itself; for "other destination systems" it "generally requires cooperation with such systems" (Apache Kafka design). An SMS gateway is such a system, and it does not cooperate.
  • Uber's push platform, at more than 250,000 messages a second, provides an "'at-least-once' guarantee" for delivery (the same Uber post).

The unavoidable gap is between the provider accepting a message and your worker recording that it did. If the worker crashes in that moment, the message looks unsent and will be retried. The user gets two copies, and nothing on your side can know which happened.

What you can do is make every other duplicate harmless:

  1. Deduplicate at ingestion. The caller sends an idempotency key, such as a UUID or a hash of user, event type and event ID. Store it with a 24-hour expiry (Redis SET key 1 NX EX 86400) and drop repeats. Stripe's API uses the same idea for payments: a retry with the same key returns the saved result instead of acting again (Stripe idempotent requests).
  2. Record sends per notification and channel. Before calling the provider, check a send log keyed on notification ID plus channel; after a success, write to it. A redelivered queue message then finds the record and stops.
  3. Let the provider merge what it can. Reuse the same apns-collapse-id or FCM collapse key when resending the same notification, so a duplicate replaces the first on the device instead of appearing beside it.

That leaves the crash window above, which is small and rare. For most notifications a rare duplicate is acceptable, and a duplicated OTP message carries the same code, so it confuses no one.

How do you stop a notification system from spamming users?

Put the user's rules in front of the queues, so a message that should not be sent never takes up queue space or provider quota. A preference service usually answers four questions:

  • Has the user opted out of this category on this channel? Then drop it. For marketing email, Gmail requires bulk senders to offer unsubscribe "in one click" (Google, 2023).
  • Is it quiet hours for the user's time zone? Then hold anything below P0 until the window ends.
  • Has the user hit a frequency cap, such as three marketing pushes a day? Then drop or defer it.
  • Can it be batched? Ten "someone liked your post" events in five minutes are better as one digest, which is what LinkedIn's system does when it groups reminders into a single email.

Rate-limiting the calling services matters as much as rate-limiting users. A bug in one upstream service that loops over the user table can send millions of notifications in minutes; a per-service token bucket at the ingestion API, like the one in the rate limiter template, caps the damage. Fan-out works the same way it does in a news feed design: one event for a large audience becomes millions of per-user messages, so expand it in batches through the queue rather than in a single request.

What should you monitor?

Measure what the user experiences, per priority and channel:

  • Age of the oldest message in each queue. Depth says how much work is waiting; age says how late it already is. Alarm when P0 age passes a few seconds.
  • End-to-end latency from event to provider acceptance, at the 99th percentile, per priority.
  • Provider error rate by status code. A rise in 429s means you are over quota; a rise in 5xx or timeouts means the provider is in trouble and the circuit breaker should be watched.
  • Invalid token rate. A jump after an app release can mean the app is not registering tokens correctly.
  • DLQ depth and email spam rate. Anything in the DLQ is a message that will never be sent without action, and Google asks senders to stay below a 0.10% spam rate and never reach 0.30%.

A checklist for a notification system design

  1. Require an idempotency key on every request and deduplicate at ingestion.
  2. Check opt-outs, quiet hours and frequency caps before enqueueing.
  3. Give P0 its own queue and workers; split queues by channel.
  4. Size against provider quotas (FCM, APNs, SMS sender numbers, email reputation), not only your own throughput.
  5. Retry only 429, 5xx and timeouts, in one place, with exponential backoff, full jitter and a per-priority attempt limit.
  6. Use short timeouts and a circuit breaker per provider, with a fallback provider for SMS and email.
  7. Delete unregistered device tokens as soon as the provider reports them.
  8. Treat delivery as at least once; record sends per notification and channel; use collapse IDs.
  9. Send exhausted messages to a dead-letter queue with an alarm and a redrive plan.
  10. Alarm on queue age per priority, not only on depth.

You can try these effects without building the system. The notification system template in StackMonkey, a free browser-based system design simulator, models priority queues, an SMS provider outage and the circuit breaker, so you can watch an OTP queue drain while a marketing burst backs up behind it. All 10 system design templates open in the simulator the same way.

About this article

Written by the team that builds StackMonkey. The traffic figures (500 million a day, a 50,000 a second peak, an SMS worker pool of 100 threads at 200 ms per send, 1-second and 2.5-second timeouts) are illustrative and come from the site's notification system template. The 10-minute campaign and the 30,000 a second push drain are assumptions made for this article. The arithmetic follows from those figures. Provider limits and behaviour come from each vendor's documentation, linked inline, as of November 2026. Limits change, so check the current pages before relying on a number. If you find an error, email [email protected] and we will correct it. More about the project is on the about page, and all articles are on the blog.

Sources

Break the notification system yourself

Open the template, start a marketing burst, take the SMS provider down and watch what happens to the OTP queue.