Sending one email is a function call. Sending the right message, to the right people, on the right channel, at a time they are willing to receive it, exactly once, and being able to prove afterwards what happened, is a subsystem. Most products discover the difference the week a customer asks why they never got the password reset, and nobody can answer.

This article is the reference our portal, logistics, booking and streaming articles point to when they say "and then the system notifies the user." It follows one notification through its whole life, from the business event that causes it to the delivery receipt that closes it, and stops at each place where real systems duplicate, drop, delay or misdirect messages.

A notification system is a decision engine that occasionally sends a message. Most of its work is deciding not to.

The Nine Stations of a Single Message

Every notification passes the same stations, whether the product sends ten messages a day or ten million:

  1. Event. Something happened in the domain: an invoice became overdue, a shipment was delayed, a comment mentioned someone.
  2. Recipient resolution. Who should hear about it? The invoice's billing contacts, the shipment's watchers, the mentioned user.
  3. Preference evaluation. For each recipient: do they want this category, on which channels?
  4. Scheduling. Now, later (quiet hours), or folded into a digest?
  5. Rendering. Template, locale, tenant branding, and the content each channel can carry.
  6. Dispatch. Hand off to an email, SMS or push provider, or write to the in-app inbox.
  7. Feedback. Delivery receipts, bounces, complaints and unregistered device tokens arrive back by webhook.
  8. Suppression updates. Hard bounces, opt-outs and dead tokens change what future sends are allowed.
  9. Record. Every decision and outcome is written down, because "why didn't I get it?" will be asked.

The rest of this article is those stations in order. The structural point is visible already: only one of the nine sends anything.

Events In, Intents Out

The first design decision is separation. Business code should publish a domain event, invoice.overdue, and know nothing about who gets told or how. A notification layer subscribes to events and turns them into notification intents. Calling Mail::send from inside the invoicing code feels quicker and becomes a problem the first time product wants an SMS variant, a digest, or a preference toggle.

Reliability starts at the same boundary. Publish the event after the business transaction commits, and a crash in between loses the notification silently. Publish it before commit and the transaction rolls back, a customer is told about something that never happened. The fix is the transactional outbox: write the event to an outbox table in the same transaction as the business change, and let a relay publish it afterwards, the same pattern behind the durable timers and retries in our workflow engines reference.

One row per recipient, per channel

From there, the core object is a notification record for each recipient on each channel, with a small state machine:

  • pending: created, not yet evaluated against preferences and schedule;
  • scheduled or held_for_digest: deferred by quiet hours or folded into a digest;
  • suppressed: deliberately not sent, always with a reason (opted out, quiet hours expired it, bounced address, duplicate);
  • sent: accepted by the provider, with the provider's message id;
  • delivered, bounced, failed: terminal states set by provider feedback or exhausted retries.

"Suppressed with a reason" is the state teams forget to model, and it is the one support needs most.

Fan-Out Without Melting the Queue

Recipient resolution is where volume appears. A tenant-wide announcement, a price drop matching thousands of saved searches, or a delayed flight affecting every passenger turns one event into tens of thousands of notifications. A single job that loads every recipient and sends in a loop will time out, retry from the beginning, and send the first half twice.

The patterns that hold up:

  • Fan out in pages. The event job resolves recipients with a cursor and dispatches one job per batch. Each batch job is small, retryable and independent.
  • Make duplicates impossible, not unlikely. A unique constraint on (event_id, recipient_id, channel) means a retried batch inserts nothing new. Pass the same key to providers that accept an idempotency key.
  • Separate lanes by urgency. One-time passcodes and password resets get their own queue and workers. A bulk announcement must never sit in front of someone trying to log in.
  • Respect provider rate limits per lane. SMS and email providers throttle by account and sender; a token-bucket limiter in front of dispatch is cheaper than handling throttling errors.
  • Store broadcasts once for the in-app feed. An announcement to every user in a tenant can be one row joined at read time, rather than fifty thousand inbox rows written at once. Personal notifications are still written per recipient, because they carry per-recipient read state.

Saved-search alerts are the classic high-fan-out case, and the reason we called notifications "the invisible product" in our real estate portal deep-dive.

Preferences Are a Matrix, Not a Toggle

A single "email notifications on/off" switch fails both ways: users who want only billing alerts turn everything off, and then miss the security alert. Preferences are a matrix of category by channel, with defaults per category:

CategoryIn-appEmailPushSMSUser can disable?
Security (new login, password changed)OnOnOnOffNo: always at least one channel
Billing (payment failed, invoice ready)OnOnOffOffChannels only
Assigned to meOnOnOnOffYes
Comments on items I watchOnDigestOffOffYes
Product newsOnOff until opted inOffOffYes

Resolving the effective setting for one recipient follows a fixed precedence, and writing it down prevents months of arguments:

  1. System rules: mandatory categories cannot be silenced entirely, and legal opt-outs (an SMS STOP, an email unsubscribe from marketing) cannot be overridden by anyone.
  2. Tenant policy: in a multi-tenant product, a customer's admin may disable a channel for the whole organisation, setting a ceiling for every member.
  3. The user's choice for that category and channel.
  4. Per-object subscriptions: watch this project, mute this thread.
  5. The category default.

Consent is data, not a flag. For SMS in particular, rules such as the US Telephone Consumer Protection Act make the record of how and when someone opted in something you need to be able to produce. Store the source, timestamp and wording of each opt-in, and mirror carrier-level STOP replies back into the preference record, so your system never tries to text someone who has already opted out at the carrier.

Quiet Hours Run on the Recipient's Clock

A non-urgent push in the middle of the night trains people to disable push entirely. Quiet hours are the defence, and they have three details that are easy to get wrong:

State diagram for one notification record per recipient and channel. A pending record is sent immediately, deferred by quiet hours or a digest, or suppressed if the recipient opted out; a deferred record is sent if still true or suppressed if not, and a sent record ends as delivered, bounced or failed.
Deferred messages are re-checked at send time and suppressed, with a reason, if they no longer hold.
  • Whose time zone. The recipient's, not the server's and not the tenant's head office. A team spread across continents has many nights.
  • What breaks through. Passcodes, security alerts and anything the user is actively waiting for are never deferred. Everything else is marked with an urgency at the category level, not decided per message by whoever writes the trigger.
  • Revalidation at send time. A deferred notification must be checked again when its window opens. "Your approval is needed" is wrong the next morning if a colleague approved it at midnight. Re-evaluate the triggering condition, and suppress with a reason if it no longer holds.

The third point applies to every delayed send, not just quiet hours. Anything that waits should ask "is this still true?" before it speaks.

Digests: Batching Without Losing the Point

Digests turn many low-urgency messages into one useful one. They work when they are built around an aggregation key, not a timer alone:

  • Group by the thing the user cares about. "12 new comments on the Henderson proposal" is useful. Twelve comments in sequence are noise.
  • Hold, then build. Eligible notifications enter held_for_digest; a scheduled job per recipient, at their local digest time, collects held items, renders one message, and marks every included item with the digest id. Building the digest idempotently means a retry never sends two.
  • Escape the digest when urgency rises. If a held item becomes urgent (the comment is now an @mention, the delay is now a cancellation), it leaves the digest and goes immediately.
  • Collapse on the device as well. Push providers support replacing an earlier notification instead of stacking a new one: the apns-collapse-id header on Apple's service, the collapse key on Firebase Cloud Messaging for Android. A shipment's ETA should update one notification, not leave five on the lock screen.

Each Channel Fails in Its Own Way

Channels are not interchangeable pipes. Each offers different guarantees about delivery and fails differently:

ChannelWhat "sent" provesTypical failureWhat the system should do
EmailThe provider accepted it, not that it reached the inboxHard bounces, soft bounces, spam-folder placement, complaintsSuppress the address on hard bounce or complaint; retry soft bounces through the provider; track complaint rates by category
SMSThe provider accepted it; delivery receipts vary by carrier and countryCarrier filtering, unregistered senders, invalid numbers, cost surprises from long messagesRegister senders where required (in the US, A2P 10DLC for application traffic on standard numbers); keep messages within one segment, which is 160 GSM-7 characters or 70 if any character forces Unicode
PushApple or Google accepted it for a token; display is never guaranteedExpired or rotated tokens, notifications disabled at OS level, uninstalled appsDelete tokens the service reports as unregistered; refresh tokens on every app launch; never rely on push alone for anything that matters
In-appIt was written to your databaseThe user does not open the appTreat the inbox as the record of truth; other channels point back to it

The last row is the design anchor. In-app is the only channel you fully control, so it should hold every notification, and email, SMS and push should be treated as ways of drawing attention to it.

Deliverability Is Reputation You Rent

Email delivery depends on the sending domain's reputation with mailbox providers, and that reputation is shared by every message the domain sends. The infrastructure decisions that protect it:

  • Authenticate everything. SPF, DKIM and DMARC, aligned with the visible From domain. Major mailbox providers now require authentication from bulk senders and filter unauthenticated mail aggressively.
  • Separate transactional from marketing. Send from different subdomains, and ideally different provider streams. A marketing campaign that draws complaints should not throttle password resets.
  • Support one-click unsubscribe. Bulk and marketing mail should carry List-Unsubscribe and List-Unsubscribe-Post headers as defined in RFC 8058, which large mailbox providers expect from bulk senders. The unsubscribe should map to a category in your preference matrix, not to "all email".
  • Keep one suppression list across providers. If you fail over to a second provider, it must know every address the first one learned to stop sending to.
  • Let tenants send as themselves properly. In a multi-tenant product where customers want mail from their own domain, build a domain-verification flow that publishes DKIM records on their DNS. Sending "from" a domain you have not verified is spoofing, and filters treat it that way.

Provider Outages and the Second Route

Email and SMS providers have outages and regional incidents. For transactional traffic, a second route is worth having:

  1. Put providers behind one internal interface per channel, so dispatch code names a channel, never a vendor.
  2. Classify errors. Retry timeouts and 5xx responses with backoff; never retry an invalid recipient or a rejected template, which will fail identically forever.
  3. Open a circuit after repeated failures and route transactional traffic to the secondary provider, keeping bulk traffic queued rather than failing it over.
  4. Ingest provider webhooks idempotently, verify their signatures, and accept that they arrive out of order: a delivery receipt can arrive before your own "sent" write has committed.

What a Lock Screen Should Never Show

Notifications are displayed in places the product does not control: lock screens, shared family tablets, email previews, smartwatch faces. Content rules follow from that:

  • Sensitive domains notify about, not with. "You have a new message from your care team" rather than the message itself. Our patient portal guide covers why health data in particular stays behind the login.
  • Links that sign people in expire quickly and work once. Forwarded emails are common.
  • Render with the right tenant. A template rendered under the wrong tenant context sends one customer's branding, or worse, one customer's data, to another's users. The tenant comes from the notification record, never from ambient state in a worker.
  • Re-check access at render time. If a user lost access to a project yesterday, today's digest must not summarise it. Recipient resolution should apply the same permission checks as the product itself, described in our RBAC reference.

The Timeline That Answers "Why Didn't I Get It?"

The best test of a notification system is a support agent with one user's complaint. They should be able to open a timeline for that user and see, without engineering help:

  • the event that should have triggered the message, and when;
  • the preference decision, with its reason: sent, suppressed because email was disabled for this category, deferred by quiet hours, folded into the morning digest;
  • the provider message id, and every delivery event received for it;
  • any suppression on the address or device, and when it was added.

Aggregated, the same records give the operational metrics that matter: delivery and bounce rates by channel and category, time from event to delivery for urgent lanes, opt-out rates by category (a rising one means a category is too noisy), and suppressed messages counted by reason, which shows how much of the system's work is deciding not to send.

Notifications look like a feature on a roadmap and behave like infrastructure in production. We design them as part of our web application development work, alongside the workflows that trigger them. If your product's messages are unreliable, noisy or impossible to trace, we would be glad to help you rebuild the pipeline.

Frequently Asked Questions

How do you stop users from getting duplicate notifications?

Make duplicates impossible rather than unlikely. Fan recipients out in small, retryable batch jobs, and put a unique constraint on event, recipient and channel so a retried batch inserts nothing new; pass the same key to providers that accept an idempotency key. Build digests idempotently too, and use the collapse options on Apple's and Google's push services so an update replaces an earlier notification instead of stacking.

Should notification preferences be a single on/off switch?

No. A single email switch fails both ways: users who want only billing alerts turn everything off and then miss the security alert. Preferences should be a matrix of category by channel, with defaults per category, resolved in a fixed order: system rules and legal opt-outs, tenant policy, the user's choice, per-object subscriptions, then the category default. Security alerts always keep at least one channel.

How should quiet hours work for notifications?

Quiet hours run on the recipient's time zone, not the server's or the tenant's head office. Passcodes, security alerts and anything the user is actively waiting for are never deferred, and everything else carries an urgency set at the category level. When a deferred notification's window opens, the system re-checks the triggering condition and suppresses the message, with a reason, if it no longer holds.

How do I improve deliverability for transactional email?

Authenticate everything with SPF, DKIM and DMARC aligned with the visible From domain, and send transactional and marketing mail from separate subdomains, ideally through separate provider streams, so a campaign that draws complaints cannot throttle password resets. Support one-click unsubscribe on bulk mail, keep one suppression list across providers, and let tenants send from their own domains only through a verification flow that publishes DKIM records.

Can I rely on push notifications for important messages?

No. When Apple or Google accepts a push for a device token, that proves only that it was accepted; display is never guaranteed. Tokens expire or rotate, users disable notifications at the operating-system level, and apps get uninstalled. Treat the in-app inbox as the record of truth, since it is the only channel you fully control, and use email, SMS and push to draw attention to it.

Sources