What you'll learn: By the end of this lesson you will be able to design a notification pipeline from event to delivery receipt, separate urgent from bulk traffic into lanes, explain what push, email and SMS each promise (and do not), set expiry and collapse rules so stale messages are never delivered, classify failures into retry and stop, and feed bounces and invalid tokens back so the system stays healthy.
An airport announces a gate change and a duty-free sale through the same speakers. If the sale announcement takes ten minutes to read out, the passengers who needed the gate change miss their flight. Good airports keep the two apart, say the gate change at once, and repeat it only while it is still true.
A notification system is that announcement desk for software. This is an educational reference design, not the verified internal architecture of any company. The ShopStream stage on search, notifications and media introduced preferences and de-duplication keys. This lesson treats the pipeline itself: lanes, channel semantics, expiry, retries and the feedback loop. It builds on message queues and pub/sub.
Verified on 2026-12-02 against RFC 8030, RFC 8058 and the Firebase Cloud Messaging, Amazon SES and Amazon SNS documentation. No code on this page was run.
The core idea
A notification system turns events into at most one useful message per person per channel, on a lane that matches how urgent it is, and it learns from every outcome. Each word carries a rule. "Useful" means perishable messages expire. "Lane" means bulk traffic can never delay urgent traffic. "Learns" means a bounce, a complaint or an invalid token changes what the system sends next.
Three illustrations run through the lesson, each labelled:
- Minimal example: one "out for delivery" push, from event to receipt.
- Realistic example: ShopStream sending a flash-sale campaign while order updates keep flowing.
- Failure example: a retry loop that keeps mailing dead addresses until the provider throttles the whole account.
The shape of the pipeline
The system has five jobs, best kept in separate components:
- Intake. Accept a request such as "send
order_out_for_deliveryto shopper 31 for order 9917": ids and a type, never finished text, plus an idempotency key so a retry is not a second request (see idempotency keys and safe retries). It usually arrives from a domain event; publishing that event reliably is the job of the transactional outbox, a separate lesson. - Decide. Check preferences and consent, the de-duplication key and per-user limits, and pick channels. This is where to drop a message cheaply.
- Render. Fill the template for the type, channel and language as late as possible, so the data is fresh.
- Dispatch. Put the message on a lane; channel workers hand it to a provider.
- Learn. Receive receipts, bounces and complaints, update the status record, and prune bad addresses and tokens.
Figure 1. The five jobs as components. How to read this: the top row is the send path and the bottom row is the learning path. Providers are drawn muted because the system does not control them: it can only call them and listen to what they report back.
Minimal example (illustrative). The order service emits "order 9917 out for delivery". Intake records it under the key order-9917-out-for-delivery, Decide finds push enabled and no duplicate, and Render produces "Your courier is 10 minutes away". A push worker sends it on the critical lane, the provider accepts it, and later reports receipt. One status row is written per step.
Lanes: why one queue is not enough
Suppose a campaign addresses 2,000,000 shoppers and workers can send about 2,000 messages per second (both illustrative). That is 2,000,000 / 2,000 = 1,000 seconds, about 17 minutes. In a single first-in-first-out queue, an "out for delivery" message created one minute into the campaign waits behind the rest of it, roughly 16 minutes. This is head-of-line blocking.
The fix is separate lanes: independent queues, each with its own workers and its own rate budget.
| Lane | Carries | Latency goal (illustrative) | Behaviour under overload |
|---|---|---|---|
| Critical | Security codes, courier at the door | Seconds | Protected capacity; never shed |
| Standard | Order progress, receipts | Under a minute | Delay a little, collapse duplicates |
| Bulk | Campaigns, digests | Minutes to hours | Slow down or pause first |
Two details make lanes work. First, capacity is reserved: if bulk and critical workers share one pool, the bulk backlog still takes the threads. Second, a campaign is not expanded all at once. Intake stores one campaign job (segment, template, send window), and a fan-out worker pages through the segment, writing per-recipient records at a rate the bulk lane can drain. Memory stays flat and an operator can pause the job. This is backpressure at the product level, and it gives you a lever when a provider throttles you: slow the bulk lane, keep the critical one.
What each channel actually promises
The pipeline treats channels uniformly, but "sent" means different things on each. Most notification bugs are a misreading of one of these promises.
| Channel | "Accepted" means | Delivery evidence | Key controls |
|---|---|---|---|
| Web push (RFC 8030) | The push service took the request; the response code 201 "does not indicate that the message was delivered" |
Optional receipts: ask with the Prefer: respond-async header; the user agent's acknowledgement produces a receipt |
TTL (required), urgency, topic |
| Mobile push (FCM) | FCM stored the message for the device | Not the same as the app showing it | TTL, collapse key, priority |
| The next mail server took the message | Later, asynchronous bounces, complaints, delivery events | Authentication, unsubscribe header | |
| SMS | The provider took the request | Carrier-dependent status reports, often incomplete | Cost per message; provider rules |
For SMS, read your provider's documentation for status reports and sender rules, and treat a missing report as "unknown".
Push: perishable by design
A push is a promise to try, within a time limit. In RFC 8030 the application server must send a TTL (time to live) in seconds, and the specification says that once the TTL elapses the push service "MUST NOT attempt to deliver" the message. It also says the push service should keep retrying until then. A TTL of zero means deliver only if the device is reachable now; if not, the message expires and is never delivered. Firebase Cloud Messaging has the same idea: a maximum of 28 days (2,419,200 seconds), a four-week default when you set nothing, and a TTL of 0 means a message that cannot be delivered immediately is discarded rather than stored.
Two more controls matter:
- Urgency (RFC 8030): four values from very-low to high, default normal. The push service does not forward the header to the device.
- Collapse. RFC 8030's
Topicheader (at most 32 characters) means a new message "replaces any outstanding push message with an identical topic". FCM's collapse key does the same: an undelivered message with the same key and registration token is discarded and the new one takes its place; with no collapse key, both are stored for later delivery.
The consequence is a design rule: give every message type an expiry and, where only the latest value matters, a collapse key. "Courier is 10 minutes away" should expire in minutes and collapse with the next ETA. A phone switched off for two days should not buzz with six stale ETAs.
Email: slow, asynchronous, and reputation-bound
Email separates "the next server took it" from "it arrived", and failures come back later. Amazon SES's documentation names the cases:
- A hard bounce is a persistent failure, such as a mailbox that does not exist. SES does not retry them (apart from DNS lookup failures) and "strongly" recommends you do not make repeated attempts to those addresses.
- A soft bounce is temporary (a full mailbox, throttling, a timeout); SES retries several times and then stops.
- A complaint is a recipient marking the message as spam, relayed through a feedback loop; the documentation recommends not retrying addresses that complain.
- Excessive bounces and complaints can reduce your sending quotas or end the account.
That is why feedback must change behaviour: a hard bounce puts the address on your own suppression list, and a complaint suppresses marketing to it. SES also keeps a global suppression list of recently hard-bounced addresses, for up to 14 days, and treats a send to a listed address as a hard bounce.
Marketing mail also needs an easy exit. RFC 8058 defines one-click unsubscribe: the message carries a List-Unsubscribe header with a single HTTPS URI and a List-Unsubscribe-Post header whose value is List-Unsubscribe=One-Click, and both headers must be covered by a valid DKIM signature. The mail client sends an HTTPS POST, so your endpoint must handle POST, must not redirect, and must not depend on cookies; the URI should identify the recipient and list without a login.
Delivery states
A notification is not a boolean. It moves through states, and each arrow is a thing your code must handle.
Figure 2. The lifecycle of one attempt. How to read this: every message ends in exactly one of four final states. "Accepted" is not final, because the provider may still report a bounce. A message stuck in Accepted with no receipt is "unknown", and a sweeper should move it to Expired after the type's expiry.
Recorded states answer "why did I not get a message?": suppressed by quiet hours, expired while offline, failed on an invalid token.
Retries: separate "try again" from "stop"
Retrying is right only when the next attempt can plausibly succeed. Group errors like this:
- Retry later: timeouts, provider server errors, throttling (HTTP
429). Back off with jitter (timeouts, retries, backoff and jitter) and honour aRetry-Afterheader when the provider sends one. - Stop and clean up: a hard bounce, an unregistered or expired device token. FCM reports an uninstalled app with a
NotRegisterederror and invalidates the token; RFC 8030 uses404for an expired subscription. Retrying these only burns reputation and budget. - Stop and fix: a malformed payload or bad credentials. Another retry gives the same answer; alert instead.
Amazon SNS shows a policy shape: four phases (immediate retries, a short fixed delay, exponential backoff, a long fixed delay) with jitter. For HTTP/S endpoints it treats every 5xx and 429 as retryable and all other errors as permanent. For SMTP, SMS and mobile push the documented default is 50 attempts over six hours, then it discards the message unless a dead-letter queue is attached. Copy the structure, not the numbers: a notification's retry window must end at its own expiry, which for a courier ETA is minutes.
Work worth a human look goes to a dead-letter queue (dead-letter queues and retries). Retries count against the lane's budget, and a circuit breaker per provider (circuit breaker and bulkhead) stops workers hammering a failing provider; otherwise an incident becomes your own retry storm (load shedding and retry storms).
Duplicates and ordering
Queues deliver at least once (Amazon SES says so for its own message copies and tells you to design for idempotence), so the de-duplication key (event, recipient, channel) must be checked and recorded in a way that survives a worker crash; see delivery guarantees. Ordering is mostly not worth buying: carry a version from the source event and drop an update older than the newest already sent for that order and channel. Collapse keys do part of this job on the device.
Failure example: the dead-address loop
A newsletter job treats every error as retryable. Old addresses that hard-bounce are retried on the full schedule, the bounce rate stays high, the provider lowers the account's quota, and critical email shares that account. The retry policy is wrong for permanent errors. The cure is the feedback loop: classify, suppress, and keep transactional and marketing mail on separate sending identities.
Trade-offs
| Decision | Gain | Cost | Wrong when |
|---|---|---|---|
| Separate lanes with reserved workers | Urgent messages stay fast | Idle capacity; more to operate | Volume is tiny and one queue never backs up |
| Render at send time | Fresh data, template fixes apply | Render must be fast and fail safe | Payloads must be auditable exactly as composed |
| Short expiry per type | No stale messages | Some users miss a message they would have wanted | The message is a record, such as a receipt |
| Collapse keys | Less noise, fewer sends | Intermediate states are lost | Every step matters, such as an audit trail |
| Fail over to a second channel | Higher chance of reaching the user | Cost, and consent for that channel | The user opted out of it |
type and channel?"} B -->|no| X["Suppress and record"] B -->|yes| C{"Past its expiry
or superseded?"} C -->|yes| X C -->|no| D{"Marketing outside
the allowed window?"} D -->|yes| H["Hold and reschedule"] D -->|no| E{"Urgent?"} E -->|yes| L1["Critical lane"] E -->|no| L2["Standard or bulk lane"]
Figure 3. A first-pass send decision. How to read this: each question is cheap and removes a message before it costs anything. The urgent test comes last because a message that must not be sent should never reach a fast lane.
In practice: a flash sale next to live deliveries
This is an educational scenario on ShopStream with illustrative numbers.
This is a realistic scenario, not a case history.
The situation
ShopStream (illustrative: 2,000,000 daily users) runs a weekly flash-sale campaign. On campaign day "out for delivery" pushes arrive up to 15 minutes late.
Starting architecture
Figure 4. The starting design. How to read this: both producers write to one queue and one worker pool, so the campaign's 1,000-second drain time becomes the latency of every other message.
Options considered
| Option | Gain | Cost | Wrong when |
|---|---|---|---|
| A. Add workers | Drains faster | The provider throttles; cost rises; blocking is only shorter | The provider rate is the limit |
| B. Priority inside one queue | One queue to run | Low priority can starve | The broker does not enforce priorities |
| C. Separate lanes, reserved workers, paged campaign fan-out | Urgent traffic is isolated; campaigns are pausable | Two to three pools to size and monitor | Volume never causes backlog |
The decision
Option C. Intake routes by message type to a lane. Campaigns become a job paged into the bulk lane at a configured rate, with quiet hours and per-user caps applied before a message is queued. Every message type gets an expiry (courier ETAs: minutes; campaigns: the end of the sale) and ETA updates share a collapse key.
Rollout and verification
Shadow first: route a copy of order events through the new critical lane and compare latency with the old path. Then move standard traffic, then the next campaign at a low rate, raising it in steps. Verify with per-lane metrics: queue age, send success, provider error rate, and messages expired before sending.
The 2 a.m. failure
The page reads: "critical lane queue age 9 minutes". The push provider has started returning 429 for the whole sender account, and the critical lane's retries sit in the same budget as the campaign.
First checks: provider error rates per lane and whether both lanes share one credential. Mitigation: pause the bulk job and let the critical lane drain; expired messages are dropped, not sent late. Follow-up: split the provider rate between lanes and make bulk fan-out slow itself on 429.
Architect's notes
- Start with the expiry table. How long each type stays true drives TTL, retry window and collapse.
- Treat receipts as events, not logs: they change future behaviour.
- Do not promise delivery. Say "handed to the provider", and "reported delivered" only with a receipt.
Common mistakes
- One queue for everything, so bulk blocks urgent.
- Retrying permanent errors, such as hard bounces and unregistered tokens.
- No expiry, so users receive hour-old "arriving now" messages.
- Treating "accepted" as "delivered". The provider's
201is only a receipt for the request. - Marketing and transactional mail on one sender identity, which shares reputation.
Key takeaways
- A notification system is a pipeline: intake, decide, render, dispatch, learn.
- Lanes with reserved capacity stop bulk traffic delaying urgent traffic; page campaign fan-out into the bulk lane.
- Each channel has its own meaning of "sent"; push is perishable (TTL, urgency, collapse), and email failures return later as bounces and complaints.
- Retry only errors that can succeed, and never beyond the message's own expiry.
- Bounces, complaints and invalid tokens must change what the system sends next.
- Record a state for every attempt so "why did I not get it?" has an answer.
Practice exercises
Exercise 1 (30 min). List ten ShopStream message types. For each, write the expiry, the lane, whether it collapses, and which channels it may use.
Exercise 2 (1 hour). Using the lifecycle in Figure 2, write the status table and the sweeper rule that moves old Accepted rows to Expired. Decide what each final state triggers.
Related reading
- ShopStream: search, notifications and media: preferences, quiet hours and de-duplication in the running project.
- Message queues and pub/sub: acknowledgements, visibility and retries.
- Dead-letter queues and retries and timeouts, retries, backoff and jitter.
- Rate limiting: per-user and per-provider limits.
- Background jobs and schedulers: the campaign job.
Official documentation
- IETF, RFC 8030: Generic Event Delivery Using HTTP Push: sections 5.2 to 5.4 and 6.
- IETF, RFC 8058: Signaling One-Click Functionality for List Email Headers.
- Firebase, Set the lifespan of a message.
- Amazon SES, Understanding email deliverability.
- Amazon SNS, Message delivery retries.