# How do you design a notification system?

By Vishal Kumar · Published 2026-09-09 · Updated 2026-11-25
Source: https://fungyaan.com/p/design-notification-system
Tags: system-design, notifications, queues, email, interview

**The verdict, which the cases below will earn:** separate deciding *what* to send from actually sending it.
- **Services call one notification API** with an event ("comment added", "invoice due") and recipients. They never call email or push providers directly.
- **The notification service applies rules:** user preferences, deduplication, quiet hours, frequency caps, and digesting.
- **Each channel has its own queue and workers** (email, push, SMS, in-app), with retries, backoff and provider rate limits, so a slow SMS provider never delays email.
- **Delivery outcomes come back** through provider webhooks: bounces and complaints suppress future sends.

The usual case file reads like this: a password reset that never arrived, a receipt sent twice, a phone that buzzed again and again at midnight. The usual suspect is the email or push provider. More often the culprit is a design where every service calls providers directly, with nobody keeping a record. Notifications look like the dullest feature in any product, and yet the design that fixes this has a nice trick at its centre: record the *intent* to notify, and let everything else (rules, channels, retries) hang off that record.

> **Case file**
>
> | | |
> |---|---|
> | **The case** | A reset that never arrived, a receipt sent twice, a phone buzzing at midnight |
> | **Suspects** | The email or push provider |
> | **Culprit** | Every service calling providers directly, with no record kept |
> | **The fix** | Record the intent to notify, then rules, a queue per channel, webhooks |
> | **Evidence** | The blogging platform's PostgreSQL email queue and suppression list |

```mermaid
flowchart LR
  SVC[Services] -->|notify event, recipients| API[Notification API]
  API --> RULES{Preferences, dedup,<br/>quiet hours, caps, digest}
  RULES --> OUT[(Outbox / notifications table)]
  OUT --> QE[[Email queue]] --> WE[Email workers] --> PE[Email provider]
  OUT --> QP[[Push queue]] --> WP[Push workers] --> PP[APNs / FCM]
  OUT --> QS[[SMS queue]] --> WS[SMS workers] --> PS[SMS provider]
  OUT --> INAPP[(In-app inbox)]
  PE -. bounces, complaints .-> HOOK[Webhooks] --> SUP[(Suppression list)]
  SUP --> RULES
```

## The pieces of the puzzle

| Piece | Job | Notes |
|---|---|---|
| **Notification API** | Accept "event X happened for users Y" | Idempotent on an event ID, so a retrying caller doesn't double-notify |
| **Templates** | Turn an event into a subject and body per channel and language | Versioned; rendered at send time with escaping for each channel |
| **Preferences** | Which channels each user wants, per category | Transactional (password reset) can't be turned off; marketing must be opt-in where the law requires |
| **Dedup and caps** | Don't send the same thing twice; don't send 50 emails in an hour | Key on (user, event type, object) within a window |
| **Digest** | Combine low-priority events into one daily or hourly message | Hold events in a table; a scheduled job builds the digest |
| **Channel queues** | Isolate channels; retry with backoff | A per-provider rate limiter in front of each provider |
| **Suppression list** | Never send again to hard bounces and complaints | Required to keep a good sender reputation |

## Case 1: transactional email

**Situation:** sign-in links, password resets, receipts. They must arrive in seconds and must never be lost. This is where the outbox pattern earns its keep.

**What I'd build:**
- Write the email to an **outbox table in the same transaction** as the change that caused it, so a crash can't lose it or send it for a change that rolled back. One move buys a lot here, and it's the elegant core of the whole design: the database's own atomicity does the hard work (the [consistency post](/p/consistency-without-2pc) compares the outbox with dual writes and sagas).
- A worker sends from the outbox with **retries and exponential backoff**, and gives up after a few hours with an alert.
- Provider **webhooks** record bounces and complaints, and the worker refuses to send to suppressed addresses.
- **SPF, DKIM and DMARC** on the sending domain; without them, much of your mail goes to spam.

The blogging platform I run works this way: emails are queued in PostgreSQL, a worker sends them with retries, and signed provider webhooks feed a suppression list. The [delayed retries post](/p/delayed-retries) covers how the queue schedules retries.

## Case 2: mobile push

**Situation:** a chat or delivery app notifies users on their phones.

**What I'd build:**
- Store **device tokens per user**, several per user, and delete tokens the provider reports as invalid.
- Send through **APNs (iOS) and FCM (Android)**; keep payloads small and free of sensitive content, since they're shown on lock screens.
- **Collapse keys**: "3 new messages" replaces earlier alerts for the same conversation instead of stacking them. Users never notice it; they only notice when it's missing.
- Respect **quiet hours** in the user's time zone for non-urgent categories.

## Case 3: digest emails

**Situation:** a collaboration tool generates dozens of low-priority events per user per day.

Digests are where a notification system shows some manners.

**What I'd build:** write each event to a pending-digest table instead of a channel queue. A scheduled job per time zone builds one email per user with everything since the last digest, and marks those rows sent. Users who were active in the app recently and already saw the events can be skipped.

## The rules that keep the case closed

- **At-least-once delivery** inside your system; **deduplicate by notification ID** at the worker, so a redelivered queue message doesn't send twice.
- **Retries only for retryable errors** (timeouts, 5xx, rate limits); never retry a hard bounce or an invalid token. Retrying those is a false lead: the answer will not change.
- **Observe each channel separately:** queue depth, send latency, failure rate per provider. A provider outage should page you before users notice.
- **Keep personal data short-lived:** delete sent message bodies after a few days; keep only what support and auditing need.

> **Remember this**
> - Separate deciding what to send from actually sending it.
> - Write the notification to an outbox in the same transaction as the change.
> - One queue per channel: a slow SMS provider never delays email.

## What to do on Monday

1. **One notification API**, idempotent on an event ID.
2. **Outbox in the same transaction** as the triggering change.
3. **A queue and workers per channel**, with backoff and provider rate limits.
4. **Preferences, dedup, caps and digests** before the queues; **suppressions** from provider webhooks.
5. **Separate dashboards and alerts per channel.**

What I like about this design is how ordinary each part is: a table, a few queues, some workers. Put them in the right order and you get a system that is calm under pressure and kind to the people on the receiving end. For how those retries are actually scheduled, the [delayed retries post](/p/delayed-retries) is the next case to read.
