Skip to content

    System Design

    Notification Systems: Lanes, Channels, Retries and Receipts

    Design a notification system: urgency lanes, push, email and SMS semantics, expiry and collapse, retries, bounces, suppression and delivery receipts.

    By Published 13 min read

    Share

    Standard lessonintermediateBackend System Design

    Before this: Message Queues and Pub/Sub

    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:

    1. Intake. Accept a request such as "send order_out_for_delivery to 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.
    2. Decide. Check preferences and consent, the de-duplication key and per-user limits, and pick channels. This is where to drop a message cheaply.
    3. Render. Fill the template for the type, channel and language as late as possible, so the data is fresh.
    4. Dispatch. Put the message on a lane; channel workers hand it to a provider.
    5. Learn. Receive receipts, bounces and complaints, update the status record, and prune bad addresses and tokens.
    Notification pipeline from event to receiptEvent sources to Intake; Intake to Decide; Decide to Lane queues (render, enqueue); Lane queues to Channel workers; Channel workers to Providers (send); Providers to Receipt handler (receipts); Receipt handler to Status store; Channel workers to Status store (log attempt)Event sources: orders, campaignsEvent sourcesorders, campaignsIntake: idempotentIntakeidempotentDecide: prefs, dedup, limitsDecideprefs, dedup,limitsLane queues: critical, standard, bulkLane queuescritical,standard, bulkChannel workers: push, email, SMSChannelworkerspush, email, SMSProviders: outside our controlProvidersoutside ourcontrolStatus store: one row per attemptStatus storeone row perattemptReceipt handler: bounces, tokensReceipthandlerbounces, tokensrender, enqueuesendreceiptslog attempt

    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
    Email 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 Topic header (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.

    stateDiagram-v2 accTitle: Lifecycle of one notification attempt accDescr: A notification is created, then either suppressed by a preference or limit, or queued. A queued message is sent to a provider and becomes accepted. An accepted message ends as delivered, or failed after a permanent error, or expired when its time to live passes. A temporary error returns it to queued with a retry delay. [*] --> Created Created --> Suppressed: preference, limit or duplicate Created --> Queued: passes the decision step Queued --> Accepted: provider takes it Queued --> Expired: time to live passes Accepted --> Delivered: receipt confirms Accepted --> Failed: bounce or invalid token Accepted --> Expired: no receipt before expiry Queued --> Queued: temporary error, retry later Suppressed --> [*] Delivered --> [*] Failed --> [*] Expired --> [*]

    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 a Retry-After header 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 NotRegistered error and invalidates the token; RFC 8030 uses 404 for 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
    flowchart TD accTitle: Should this message be sent now accDescr: A decision flow. Check whether the user consented to this channel and type. Check whether the message has expired. Check whether a newer message of the same kind already replaced it. Then choose a lane by urgency and send, or hold marketing until the allowed window. A["Event arrives"] --> B{"Consent for this
    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

    Starting architecture: one queue for every messageOrder events to One shared queue; Campaign job to One shared queue (all at once); One shared queue to Workers; Workers to Push providerOrder eventsOrder eventsCampaign job: 2,000,000 messagesCampaign job2,000,000messagesOne shared queueOne sharedqueueWorkers: 2,000 per secondWorkers2,000 per secondPush providerPush providerall at once

    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.

    sequenceDiagram accTitle: Provider throttling hits both lanes accDescr: The bulk lane and the critical lane share one sender account at the push provider. The provider returns 429 to bulk sends. Both lanes back off, so critical messages wait. Operators pause the bulk job, the provider recovers, and the critical lane drains. participant B as Bulk lane participant C as Critical lane participant P as Push provider B->>P: batch of sends P-->>B: 429 too many requests C->>P: courier push P-->>C: 429 too many requests Note over C: retries wait for the account budget B->>B: operator pauses the campaign job C->>P: courier push, retried P-->>C: accepted

    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 201 is 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.

    Official documentation

    Ask about this article

    Get answers grounded in this post. AI-generated — based on this article, and may be imperfect.

    Scaled AI Weekly

    Enjoyed this? Get more like it every Monday.

    Real architecture decisions, LLMOps patterns that survive production, and engineering leadership advice — from 12+ years of building at enterprise scale. Free. No spam. Unsubscribe anytime.

    Get new articles by email

    Free. We email a confirmation link first, and you can unsubscribe from any email.

    Join engineers building production AI systems

    Comments