# How to Design a Scalable Notification System (Push, Email, SMS)

> A notification system is an event ingester, one queue per channel, a preference check, a dedup constraint, retries into a dead-letter queue and webhook-driven delivery tracking.

URL: https://www.matthewswong.com/en/blog/design-notification-system-architecture/

- Author: Matthews Wong (https://www.matthewswong.com/en/about/)
- Published: 2026-10-10
- Updated: 2026-10-10
- Category: Backend

> **Key takeaway:** Design a scalable notification system by turning every business event into one deduplicated database row, fanning it out to a separate queue per channel (push, email, SMS), checking preferences and suppressions before sending, retrying transient failures with backoff into a dead-letter queue, throttling each provider, and updating status from provider webhooks.

The first notification feature in most systems is one function: after the order is paid, call an email API. It works until the day the provider is slow, the request times out, the job retries, and a customer receives the same receipt three times.

This post is the architecture that sits between a business event and a phone buzzing. It stays on a single stack I work with, Postgres and Redis on a modest server, and every figure below is arithmetic from the stated assumptions or taken from a provider document listed at the end, not a benchmark. Queue mechanics and outbound webhooks have their own posts here, so this one covers what is specific to notifications.

## What does a notification system actually have to do?

It has to turn a fact (order 8841 was paid) into zero or more messages on the right channels, once each, in the user's language, respecting their choices. The business code should emit only the event. Everything about channels, templates and providers belongs behind a boundary, so that adding WhatsApp later changes one worker and not forty call sites. The two payload shapes below are the contract.

Two decisions are baked into that shape. First, the template is referenced by key and version rather than rendered at enqueue time, so a retry an hour later produces the same copy, and a rendering error (SES reports one as a Rendering Failure event) is caught in the worker instead of poisoning the producer. Second, the notification row is written in the same database transaction as the business change, so an event that committed can never be lost between the commit and the queue.

## Why use one queue per channel instead of one shared queue?

Because the three channels fail in different ways, at different speeds, under different limits. A shared queue lets a rate-limited SMS provider hold back push messages that were ready to go. Separate queues give each channel its own concurrency, its own retry policy and its own backlog you can read at a glance, and a priority split inside each one keeps OTP codes ahead of campaigns.

Channel

Where status comes from

What failure looks like

Retry rule worth encoding

Push (FCM)

The response to the send request

400, 401, 403, 404 are permanent; 429 and 500 are transient

Abort on 4xx; honour Retry-After on 429, default 60 s; exponential backoff on 500; wait at least 10 s

Email (SES)

Events published to SNS: Send, Delivery, Bounce, Complaint, Reject, DeliveryDelay

A Permanent bounce means the address is dead; a Complaint means the user flagged you

Never retry a Permanent bounce; add the address to suppressions at once

SMS (Twilio)

A StatusCallback POST per status change

Status ends at delivered, undelivered or failed, with an ErrorCode

Callbacks can arrive out of order, so never let a status move backwards

The table is the reason the retry code later in this post returns a typed outcome rather than throwing. A worker that cannot tell a permanent failure from a transient one will retry a dead address eight times and train your provider to distrust your sender reputation.

## How do you handle user preferences and opt-outs?

Keep preferences and suppressions in two separate tables, because they have different authors. A preference is something the user chose, per category and per channel. A suppression is something a provider told you, such as a hard bounce, a complaint or a STOP reply, and it overrides every preference because sending anyway damages your standing. The schema below makes a missing preference row mean the default, so a new category never needs a backfill.

For email, make the unsubscribe a single request. RFC 8058 defines the List-Unsubscribe-Post header with the value List-Unsubscribe=One-Click so a mail client can unsubscribe the user with one POST, and your handler should write straight to channel_suppressions. Check the preference at the moment of sending, not at enqueue time, because a user who opts out while a job waits in the queue expects it to stop. Security and transactional categories should not be switchable off, and the UI should say so.

## How do you stop the same notification being sent twice?

Give every intended message a deterministic dedup key and let a database unique constraint decide who is first. The key is built from things that identify the intent, not the attempt: the source event id, the user and the channel, for example order-8841-paid:user-17:email. A random UUID per attempt, the usual mistake, makes every retry look like a new message.

The INSERT with ON CONFLICT DO NOTHING is atomic: PostgreSQL documents that RETURNING yields only the rows actually inserted, so zero rows means somebody already owns this key. That covers a producer that replays an event, and a queue that delivers a job twice. It does not cover the gap after the provider accepted the message but before you recorded it, which is why the next section matters.

> Exactly-once sending is not available when the provider call and your database are two systems. If the process dies after the provider accepted a message and before you store its id, the retry will send again. Where the provider accepts an idempotency key, pass your dedup key; where it does not, accept an occasional duplicate and prefer it over a lost OTP.

## How should retries and the dead-letter queue work?

Classify the outcome first, then decide. A permanent error goes straight to the dead-letter queue, because retrying a 400 only repeats the 400. A transient error is retried with exponential backoff and jitter. FCM's own guidance is to wait at least 10 seconds, to honour Retry-After on a 429, defaulting to 60 seconds, to use exponential backoff on 500s, and to stop retrying after 60 minutes.

Worked example with a 10 second base and doubling: the ceilings are 10, 20, 40, 80, 160, 320, 640 and 1,280 seconds, which sum to 2,550 seconds, about 42.5 minutes. A ninth attempt would add 2,560 seconds and end at 5,110, past the 3,600 second hour, so eight attempts is the natural cap. The dead-letter queue is not a graveyard: store the payload, the last error and the attempt count, alert on its depth, and give yourself a one-click replay for the day a provider has a bad afternoon.

## How do you respect provider rate limits and fail over?

Put a token bucket in front of every provider call, sized to the limit on your own account, and make the worker wait instead of fail when the bucket is empty. FCM, for instance, throttles with 429 once a quota bucket is exhausted, and its guidance is to ramp traffic up over at least a 60 second window rather than start at full rate. Failover is a second provider behind a circuit breaker, used only for provider-side trouble such as timeouts and 5xx, never for a bad recipient.

Arithmetic shows why priority lanes matter. Suppose an SMS account allows 20 messages a second, an assumption for illustration. A campaign of 12,000 messages takes 12,000 divided by 20, which is 600 seconds, ten minutes, and an OTP queued behind it waits up to that long. With a separate critical lane that drains first, the same OTP waits for at most a few tokens. Failover has its own cost: a timeout is ambiguous, since the first provider may have delivered, so a failed-over send can duplicate.

> Run the bucket in Redis once you have more than one worker process. An in-memory bucket per worker silently multiplies your limit by the worker count, and the first sign is a wave of 429s from the provider.

## How do you track delivery with provider webhooks?

A send call only tells you the provider accepted the message. Delivery, bounce and failure arrive later as webhooks: SES publishes Send, Delivery, Bounce, Complaint and more to SNS, and Twilio posts each status change to your StatusCallback URL. Look the notification up by the provider's message id, which is why the notifications table stores it. Twilio states plainly that callbacks are not guaranteed to arrive in the order they were sent.

So the update must only move forward. Rank the statuses and write the new one only if its rank is higher, as in the query above, otherwise a late sent overwrites delivered and your dashboard lies. Make the webhook handler idempotent too, since providers retry their own callbacks, and let terminal bad news write to the suppression table so the next send is skipped without anyone looking.

## What is the checklist before shipping a notification system?

Use this list as a review gate. Each item maps to a failure described above, and an unchecked item is a known incident waiting for a date.

1. Business code emits events only; one ingest boundary maps events to channels and templates.
2. The notification row commits in the same transaction as the business change.
3. A unique dedup key, built from intent rather than attempt, guards every insert.
4. One queue per channel with a critical lane, and a preference plus suppression check at send time.
5. Outcomes are typed; permanent errors go to the dead-letter queue, transient ones back off with jitter to a cap.
6. A token bucket per provider, a circuit breaker for failover, and forward-only status updates from webhooks.

If you can only do three on day one, do the dedup key, the preference check and the retry classification. Those three prevent the visible mistakes, namely duplicates, unwanted messages and hammering a dead address, and everything else can be added behind the same contract.

A scalable notification system is mostly a set of refusals: refuse to send twice, refuse to send to someone who said no, refuse to retry what cannot succeed, and refuse to trust the order of webhooks. Build the boundary and the constraints first and the provider choices become swappable details.

## Sources and further reading

- Firebase: best practices for sending FCM messages at scale
- Twilio: track the delivery status of outbound messages
- Amazon SES: event records published to Amazon SNS
- RFC 8058: signaling one-click functionality for list email headers
- PostgreSQL: INSERT with ON CONFLICT and RETURNING

## Source links

- https://firebase.google.com/docs/cloud-messaging/scale-fcm
- https://www.twilio.com/docs/messaging/guides/track-outbound-message-status
- https://docs.aws.amazon.com/ses/latest/dg/event-publishing-retrieving-sns-examples.html
- https://datatracker.ietf.org/doc/html/rfc8058
- https://www.postgresql.org/docs/current/sql-insert.html

## FAQ

### How do you design a scalable notification system?

Separate the event from the delivery. Business code emits an event, an ingester writes a deduplicated notification row, and a worker per channel (push, email, SMS) sends it after checking preferences. Add retries with backoff, a dead-letter queue, a rate limit per provider and webhook-based status tracking.

### Why should push, email and SMS have separate queues?

Each channel has its own provider, its own rate limit and its own failure modes. With one shared queue, a throttled SMS provider can hold back push messages that are ready to send. Separate queues let you tune concurrency and retries per channel and see each backlog on its own.

### How do you prevent duplicate notifications?

Build a dedup key from the intent, such as event id, user and channel, and put a unique constraint on it. Insert with ON CONFLICT DO NOTHING and send only if a row was inserted. Do not use a random id per attempt, because every retry would then look like a new message.

### How should a notification system handle retries and failures?

Classify the result first. Permanent errors such as a 400 or a hard bounce go straight to a dead-letter queue, while transient errors such as a 429 or 500 are retried with exponential backoff and jitter. Honour Retry-After when the provider sends it and set a maximum age, for example one hour.

### How do you track whether a notification was actually delivered?

Store the provider's message id when you send, then update the row from the provider's webhooks. SES publishes events such as Delivery and Bounce, and Twilio posts each status change to a callback URL. Callbacks can arrive out of order, so only let the status move forward.

---

- HTML version: https://www.matthewswong.com/en/blog/design-notification-system-architecture/
- Bahasa Indonesia: https://www.matthewswong.com/id/blog/design-notification-system-architecture/
- Site index for agents: https://www.matthewswong.com/llms.txt
- Sitemap: https://www.matthewswong.com/sitemap.xml
- API description (OpenAPI): https://www.matthewswong.com/openapi.json
