All posts
System Design Mastermind · Part 32
  • System design
  • Interview prep
  • Notifications
  • Push
  • Queues

Notification system design: push, email and SMS without spam, drops or duplicates

How to design a notification platform (push, email, SMS and an in-app inbox) in real interview order: transactional sends, devices and one marketing campaign against FCM's 600K-a-minute quota as the numbers that matter, an API that returns 202 with an idempotency key and takes categories instead of channels, an explainer on how a push reaches a locked phone, a Notify API, router, preferences and tokens, channel queues with a transactional lane, push and email/SMS workers built in passes, one order update walked from the order service to Riya's phone with a dead tablet token, a lab on a 180M-send campaign, priority lanes, 429s and pacing, a lab on retries, collapse ids, idempotency keys and dead tokens, a decision walker for opt-ins, caps and quiet hours, the lifecycle of a notification, and what happens when each part fails.

27 Oct 2026 · 32 min read · interactive

Share

The 1-minute answer

Every service calls one Notify API with a category, a template and an idempotency key made from the event; the API records it once and returns 202. A router then decides: dedupe, the user's preferences per category and channel, a per-user cap across all teams, quiet hours in local time, which devices are live, and the template in the user's language. It puts one job per device on durable queues per channel, with a transactional lane (OTPs, order updates) apart from bulk (campaigns). Workers hold HTTP/2 connections to APNs and FCM (and email and SMS vendors), set priority, expiry and a collapse id, retry 429s and 5xx with backoff until the expiry, and delete dead tokens on 410 or UNREGISTERED. Campaigns are paced below the provider's quota (FCM's default is 600K a minute), so OTPs keep flowing; an OTP not confirmed in time falls back to SMS. Delivery is at-least-once with dedupe, never exactly-once.

How this page follows the interview

Each phase is a section below, in the order you'd present it. Click a phase for what to say, what to write, and the trap.

✅ Seen: said publicly (cited)🔶 Inferred❓ Unknown: state it as an assumption🧭 Interview choice

This is a generic notification platform for a large consumer app (think a food-delivery or shopping app in India), built from what Apple, Google, AWS, LinkedIn, Uber and Duolingo have published. Queues, retries and idempotency were introduced in Foundations F10 and F11; rate limits in Part 12; WhatsApp's delivery ticks in Part 23 are the chat-side cousin of this problem.

Requirements and numbers

Agree the channels, then say what's strict per category. The average is easy; one marketing campaign against the push provider's quota is what shapes the design. Change any input: each number comes with the decision it forces.

Functional

  • Services send a notification to a user by category (OTP, order update, chat, offer)
  • Channels: push (iOS, Android), email, SMS, and an in-app inbox
  • Marketing schedules campaigns to segments, in local time
  • Users set preferences per category and channel, and quiet hours
  • Look up status: was it sent, to which device, was it opened

Non-functional

  • OTPs arrive within ~30 s by some channel, even during a campaign
  • Never send to someone who opted out; never show the same one twice
  • Don't lose a notification the API accepted (until it expires)
  • Stay inside provider quotas and email/SMS rules
  • A day's sends from a few million to a billion

Out of scope (say it)

Building APNs or FCM themselves, the campaign UI, segment building, the content of messages, WhatsApp business messaging.

Capacity calculator

Every input is an assumption 🔶: say it out loud. Anchors: FCM's default quota of 600K messages a minute per project ✅ Firebase docs; LinkedIn's notification system handled over 1 billion requests a day in 2018, including a ~100M daily digest batch ✅ LinkedIn 2018. Users, sends and the peak factor are teaching values.

Three rules for this estimate
  1. A day is 86,400 seconds. Divide daily totals by it, then multiply by the peak factor.
  2. Sends are per device. One notification to a person with a phone and a tablet is two provider calls.
  3. Size the campaign on its own. Audience × devices ÷ window, against the provider's quota per minute.
They'll push on thisAnswer out loud, then open.

Core entities and the API

A handful of calls. What they listen for: 202 with an id (not "delivered"), an idempotency key made from the event, and categories instead of channels.

EntityKey fieldsNote
Request
Response

Under the hood, workers call APNs at POST /3/device/<token> over HTTP/2 and FCM's v1 messages:send; producers never see either. ✅ Apple + Firebase docs

They'll push on thisAnswer out loud, then open.

High-level design

Build it in passes and say why each box exists. Click any box to see what it does, what it owns, what's inside it and what you'd watch.

How a push reaches a locked phone

  1. The app registers. On start it asks APNs (iOS) or FCM (Android) for a device token and sends it to your API with a device id. Tokens can change; send it on every start. ✅ Firebase docs
  2. Your worker calls the provider. An HTTP/2 POST with the token, a JSON payload (4 KB max on APNs), apns-priority 10 (now) or 5 (when power allows), an expiry and a collapse id. ✅ Apple docs
  3. The provider delivers or stores. It holds a connection to the phone. If the phone is offline, APNs keeps one notification per app (usually the latest) until the expiry; FCM keeps messages up to 28 days unless collapsed. ✅ Apple + Firebase docs
  4. The OS shows it, or not. Delivery is best effort: APNs may reorder, group low-priority pushes into bursts, or throttle an app the user ignores. ✅ Apple docs

Which channel for what

  • Push: free per message, instant when the phone is online; needs permission and a live token.
  • In-app inbox: always works, but only when the app is opened; the record of everything.
  • Email: receipts and digests; reputation rules (SPF, DKIM, DMARC, unsubscribe) decide if it lands. ✅ Gmail 2024
  • SMS: reaches any phone, costs money per message; in India every commercial SMS needs a DLT-registered header and template. ✅ TRAI 2024

The router chooses per category and per user; LinkedIn's ATC picks among email, SMS, desktop, in-app and push the same way. ✅ LinkedIn 2018

They'll push on thisAnswer out loud, then open.

Walk one notification, box by box

Riya ordered biryani in Hyderabad. Imran, the rider, has just picked it up, and the order service wants to tell her. She has an iPhone and an old tablet she hasn't opened in six weeks. Each step lights up the path and shows what goes over the wire, what's stored and how long it takes.

On the wire

Arrows show who calls whom, and the numbers give the order. Replies go back along the same line.

Data and database choices

One row per notification and per attempt, partitioned by user; tokens with a last-seen time, and dedupe as an atomic insert-if-absent.

DataPickConsideredWhy not those

The code to know: decide, then send

-- Router, per notification. Illustrative; no company's real code.
n = log.insert_if_absent(req.idempotency_key, req)  -- dedupe
if n.existed: return n.id
if now() > req.expires_at: return drop("expired")
p = prefs.get(req.user)                              -- cached
if not p.allows(req.category): return inbox_only(n)
if is_marketing(req) and sent_today(req.user) >= CAP: return drop("cap")
if not urgent(req) and in_quiet_hours(p, now()): return hold(n, p.quiet_end)
for d in devices.live(req.user):
    enqueue(lane(req), {n.id, d, collapse_id: n.id, expires_at})

-- Push worker, per job
r = provider.send(job)                 -- APNs or FCM
if r.ok: mark(job, "sent")
elif r.status in (410, 404 UNREGISTERED): devices.delete(job.d)
elif r.status in (429, 5xx) and now() < job.expires_at:
    retry_later(job, backoff_with_jitter(job.n))

Pseudocode. 🧭

Why this shape works

  1. Insert-if-absent is the dedupe. Two retries racing can both pass a "have we seen it?" check; only one can win a conditional insert. 🧭
  2. Partition by user. Inbox, caps ("sent today") and deletes are all per user; LinkedIn partitions its notification state by member id for the same reason. ✅ LinkedIn 2018
  3. Tokens carry a timestamp. Update it on every app start; a registration unseen for a month is stale. ✅ Firebase docs
  4. Expiry is data. It's stored with the notification and passed to providers, so nobody delivers a stale "out for delivery". ✅ Apple docs

More database questions

They'll push on thisAnswer out loud, then open.

Deep dive: the 7 pm campaign and the OTP

Marketing sends 180M pushes for a dinner offer. Meanwhile 30,000 OTPs and order updates a minute keep arriving. A priority lane orders your own queue; it can't stop the provider rejecting your OTPs when you send faster than its quota. Pick a preset, then change the numbers.

Per minute, stacked: vermilion = transactional sends accepted, ink = campaign sends accepted, red = calls rejected with 429. Dashed: the provider's quota; dotted: the campaign's deadline. A fluid model in 10 s steps: workers try up to their rate, the provider accepts up to its quota and rejects the rest at random, rejected calls go back to the front of their queue. Teaching numbers. 🧭

What the lab computes

  1. Accepted per step = min(tries, quota); every call has the same chance q = quota ÷ tries, OTP or not. 🧭
  2. OTP wait = time in the queue (one queue: behind everything released before it) + backoff after 429s. At p99 an OTP fails ⌈ln 0.01 ÷ ln(1 − q)⌉ − 1 times, waiting 1 + 2 + 4 … s (capped at 60 s). 🧭
  3. Pace = pace% × min(workers, quota) − transactional, so the provider always has room for OTPs. 🧭

What the providers say

  • FCM: 600K messages a minute per project by default; over it you get 429 RESOURCE_EXHAUSTED until the next minute. Self-serve increases up to +25%; event increases need 15 days' notice (30 above 18M a minute). ✅ Firebase docs
  • FCM per device: up to 240 messages a minute and 5,000 an hour to one Android device. ✅ Firebase docs
  • APNs publishes no fixed quota; Apple asks you to spread traffic over many connections and avoid bursts on a few. ✅ Apple docs

The campaign size, worker rate and OTP traffic are teaching values. 🧭

They'll push on thisAnswer out loud, then open.

Deep dive: never lose one, never show it twice

A timeout doesn't tell you whether the provider took the push. Retry, or you lose some; retry with the same collapse id, or you show some twice; and clean your tokens, or a sixth of your sends go nowhere.

What the lab computes

  1. Each call is acked (1 − p), failed and not delivered (p × (1 − u)), or delivered but unacked (p × u). Unacked calls are retried, up to k times. 🧭
  2. Lost = (p(1 − u))^(k+1). Copies delivered = (1 − p + pu) × (1 − p^(k+1)) ÷ (1 − p); every copy past the first is a second banner unless the collapse id merges it. 🧭
  3. Dead tokens: never cleaned, 1 − (1 − churn)^months of stored tokens are dead; cleaned on the first error, about one day's churn. 🧭

What's public

  • APNs: apns-collapse-id (≤ 64 bytes) merges repeats into one notification; apns-expiration 0 means try once, don't store. ✅ Apple docs
  • Apple DTS: "410 Unregistered is an irrecoverable and final error"; remove the token. ✅ Apple forums
  • FCM: delete on UNREGISTERED (404); a registration unseen for a month is stale; apps that don't manage tokens lose about 15% of messages to inactive devices. ✅ Firebase 2024
  • Uber's RAMEN (in-app push): at-least-once with sequence numbers, retried until each message's TTL. ✅ Uber 2020

Failure, ambiguity and churn rates are teaching values; the 0.7% churn over 24 months is set to land near Firebase's 15%. 🧭

They'll push on thisAnswer out loud, then open.

Deep dive: should this notification be sent?

Most notifications that annoy people were technically delivered perfectly. The router runs the same checks, in the same order, for every notification: dedupe, opt-in, cap, quiet hours, then a live device. Pick a case and change the user's settings.

CheckWhy

What's public

  • LinkedIn ATC filters duplicates, expired and already-acted-on notifications, rate-limits upstream apps, aggregates related ones into one, picks the channel and optimises delivery time by locale; member complaints halved. ✅ LinkedIn 2018
  • Duolingo picks among reminder templates with a bandit that penalises templates the user saw recently (half-life ~15 days); DAU +0.5% in a two-week A/B test. ✅ Duolingo KDD 2020
  • Gmail: senders of ~5,000+ messages a day need SPF, DKIM, DMARC and one-click unsubscribe for marketing, and must keep spam reports under 0.3%. ✅ Google 2024

Quiet hours 22:00–08:00, a cap of 2 offers a day and the outcomes per category are interview choices. 🧭

They'll push on thisAnswer out loud, then open.

A notification's lifecycle

A notification moves from accepted to queued to sent, and may be held, suppressed, retried, expire or fall back to SMS. Click events to move it; ones that can't happen from the current state are disabled. Each event shows what fires across the system.

NormalSomething went wrongGreyed out: not possible from the current state.

Edge cases interviewers love

They'll push on thisAnswer out loud, then open.

Failure, monitoring and recovery

A notification system fails quietly: requests return 202 while OTPs sit in a queue or in backoff. Click a box to take it down: red is the failed part, amber is its blast radius. Each answer covers impact, degraded mode, the alert, automatic and manual recovery, and how you'd trace it.

Tracing it back: a normal OTP vs one during the campaign

Every span carries the notification id. Times are seconds from the producer's call. In the bad trace the campaign shared one queue with OTPs and workers were sending above FCM's quota.

How one failure becomes three

What you'd alert on (SLOs)

SignalTargetAlert

Big-night playbook

    The toolkit

    Name the technique, then say where it goes in this design.

    They'll push on thisAnswer out loud, then open.

    Making it fast, and who owns what

    Your own path is milliseconds; the provider and the phone are most of the time, and a held notification waits hours on purpose. Bars are sizing estimates, not measured figures.

    TeamOwnsPaged when…

    Senior follow-ups beyond the happy path

    Interviewers pick from these themes once the design is on the board. Have one concrete answer per theme, tied to this design.

    Practice ladder

    Real interviews go level by level. Answer out loud before opening each one. Levels 6–7 are where Senior becomes Staff.

    Sources

    Checked October 2026. Provider rules come from official docs: Apple's "Sending notification requests to APNs" (HTTP/2, apns-priority 10/5/1, apns-expiration, apns-collapse-id up to 64 bytes, 4 KB payloads, one stored notification per app while offline, best-effort delivery) and an Apple DTS answer on the developer forums (410 Unregistered is final); Firebase's throttling-and-quotas page (600K messages a minute per project, 240 a minute and 5,000 an hour per Android device, 20-message collapsible bursts, quota increases with 15 or 30 days' notice), token-management guide (stale after a month, Android expiry after 270 days, delete on UNREGISTERED) and message-lifespan page (TTL up to 28 days), plus the Firebase Blog's July 2024 delivery post (about 15% of messages lost to inactive devices without token management). Email rules are Amazon SES's reputation docs (bounce 5% review, 10% pause; complaints 0.1% and 0.5%) and Google's sender-guidelines FAQ (5,000 a day, spam under 0.3%, one-click unsubscribe since 2024). India's SMS rules are TRAI press releases 60/2024 (30 Aug 2024: links must be whitelisted from 1 Oct 2024) and 80/2024 (sender chain declared from 1 Dec 2024); DLT categories are summarised from Plivo's docs (third party). Company designs are LinkedIn's Air Traffic Controller (1 Mar 2018), Uber's RAMEN push platform (18 Dec 2020) and Duolingo's KDD 2020 bandit paper. KodeKloud's notes are a third-party prep resource, used only to cross-check what interviewers expect. No company publishes its campaign sizes, retry policy or caps, so those are interview choices; all labs use rounded teaching values.

    System Design Mastermind · Classics

    Series home

    All of Classics

    6 published · 4 comingThe problems almost every loop draws from.

    01

    Uber system design, reverse-engineered: from tap to pickup

    In-memory geo index sharded by map cell → rank nearby drivers by road ETA → offer to one driver with a 15 s timeout → accept with compare-and-set → push updates to both apps.

    30 min · interactive Preview
    12

    Rate limiter system design: fair limits at a million requests a second

    Check every request once in the API gateway → one atomic Lua script per request on the caller's shard of a sharded Redis (token bucket for per-second, window for per-day) → 429 + Retry-After, or forward with RateLimit headers → local cache for keys already over → each rule fails open or closed on purpose.

    30 min · interactive Preview
    23

    WhatsApp system design: chat, offline delivery and the three ticks

    One long-lived encrypted connection per device → the chat server stores a copy per recipient device in a replicated offline queue, then acks (✓) → session lookup, forward or push → the device saves and acks, the copy is deleted (✓✓) → a read receipt when opened. Client-made ids and dedupe at both ends, backoff with jitter on reconnect, Sender Keys for groups.

    32 min · interactive Preview
    26

    Ticketmaster system design: selling seats without double-booking

    Cached reads for browsing → a seat inventory with one row per seat, sharded by event → a hold is one conditional UPDATE (only if free or expired) with a 10-minute timer → pay with a client-made idempotency key → confirm only if the hold is still yours, plus an outbox for tickets. A waiting room admits fans at the rate booking can serve.

    32 min · interactive Preview
    29

    News feed system design: fan-out, celebrities and ranking

    Write each post once → fan-out workers push its id into active followers' capped Redis timelines → accounts above ~1M followers are merged at read time instead → the feed service gathers ~1,500 candidates, a light model trims them, a heavy model predicts actions, a weighted sum orders them → deletes and blocks are checked at read time, pages use a cursor.

    32 min · interactive Preview
    32

    Notification system design: push, email and SMS without spam, drops or duplicates

    One Notify API with an idempotency key → a router checks dedupe, preferences, caps and quiet hours, picks live devices → per-channel queues with a transactional lane apart from bulk → workers call APNs, FCM, email and SMS with priority, expiry and a collapse id, retry 429s with backoff and delete dead tokens → campaigns paced below the provider quota, OTPs fall back to SMS.

    You're reading this Preview
    ··

    Video streaming (YouTube / Netflix)

    Coming next
    ··

    URL shortener

    Coming next

    More posts