CodingNodes Space play · ←→ step · R restart

The problem

A notification system is the part of a product that reaches a user when the user is not looking at the product. That inversion is the whole design problem: the work happens in a burst, the delivery has to land across many channels, and a single event can fan out to a hundred thousand people. Get the timing wrong and you either flood a phone or let a message sit for an hour.

The standard answer is an event-driven pipeline. The thing that happened is published as a message, a buffer absorbs the burst, a consumer renders the notification, and a router sends it to whichever channels the user opted into. We will build that pipeline piece by piece, then close the loop with one event that fans out to a crowd and lands on a phone, an inbox and a text at once.

Requirements

Functional — what it must do

  • Deliver a notification when a qualifying event occurs — a follow, a comment, a payment, a reminder — to the user(s) it concerns.
  • Support multiple channels from one event: push, email, SMS and in-app, each governed by the user's stated preferences.
  • Deliver at-least-once: a notification that the system accepted is not silently lost, even if a consumer or a channel is briefly down.

Non-functional — how well it must do it

  • Push notifications land within about a second of the event for the common case; email may be deferred to a few minutes without the user noticing.
  • Absorb bursty fan-out: one event can touch a large follower set, and the pipeline must not overload the channels or the database under that spike.
  • Dedupe so a retry never double-delivers a message the user has already seen; the user sees each notification exactly once in effect.

Scale — how much it must take

  • On the order of 50,000 events per second at peak, fanning out to hundreds of millions of notifications per day across push, email and SMS.

Assumptions — the numbers this design is sized for

A rate limit means nothing without a scale. These are the figures every later part relies on: how much traffic arrives, how much work the limiter has to do per second, and how much latency and memory it may spend doing it.

Event rate
~50,000 / s
The peak the pipeline must absorb. The buffer is sized to this, not to the average.
Fan-out
up to 100K / event
A viral event touches a large follower set. This is the burst that naive fan-out cannot survive.
Volume
~300M / day
Events times average fan-out. The per-day total, not the per-second peak, drives channel cost.
Channels
push · email · sms
Three external channels plus in-app. Each has its own latency and cost profile.
Push latency
< 1 s
The user's expectation for a push. Email and SMS have far looser budgets.
Guarantee
at-least-once
Better to over-deliver and dedupe than to drop. Exactly-once in effect, at-least-once in transport.
Retry
3× backoff
A failed channel delivery is retried a bounded number of times with increasing delay.

Takeaways

Part 1

What a notification is

Before the pipeline, fix the nouns: the event that triggers, the recipient it concerns, the channel it travels on, and the preference that decides whether it may travel at all.

  1. 1
    Event → recipient → channel

    Every notification is three things in a row. An event happens, it concerns one or more recipients, and it is delivered on one or more channels. The design that follows is just a machine for moving value along that row, reliably and at the right time.

  2. 2
    Triggers are events, not timers

    Most notifications are reactive: a follow, a comment, a payment clearing. A few are proactive: a reminder, a digest. Both are events on a timeline, which is exactly why an event-driven pipeline is the right shape — the system's job is to react to events, not to poll.

  3. 3
    Preferences are a gate, not a filter

    A user's settings decide whether a notification may be sent and on which channels. That is a gate the router consults, not a filter applied to the message. The event is still produced and buffered; the gate only decides the last hop. That separation keeps the expensive fan-out from doing work the user never opted into.

Part 2

The event-driven pipeline

Producers publish events, a broker buffers them, and consumers render and route them. The buffer in the middle is what lets a spike in events survive without a spike in delivery.

  1. 1
    Publish, don't call

    The thing that happened — a new follow — is not delivered by a direct call. The producer publishes an event to the broker and moves on. Decoupling the 'it happened' from the 'tell someone' is the whole point: the producer does not know, and does not need to know, who is listening.

  2. 2
    The broker is the shock absorber

    The broker accepts events as fast as they arrive and hands them to consumers at the rate the downstream channels can actually serve. When the event rate spikes past the delivery rate, the backlog grows in the broker rather than crashing the channels. That is the buffer doing its job.

  3. 3
    Consumers render, the router sends

    A consumer pulls an event, renders it into a concrete notification — the text, the deep link, the icon — and hands it to the channel router. Rendering and routing are separate steps so that one consumer can serve many channels and many recipients without re-doing the render.

Part 3

Push or pull

The expensive decision is fan-out: when one event concerns a huge set of recipients, do we write to every recipient's inbox now, or compute the set when each recipient reads?

  1. 1
    Push: write ahead to each inbox

    Push fan-out writes a row into every follower's inbox the moment the event happens. Reads become cheap — the feed is already there — but a single viral event writes a huge number of rows, and a user who never opens the app still pays for a write they never read.

  2. 2
    Pull: compute on read

    Pull fan-out stores only the event and assembles each user's feed when they open the app. Writes are cheap and nobody pays for a feed they never open, but every read now does a join across the actor's recent events — the cost moved from write time to read time.

  3. 3
    Pick by the ratio

    The choice is the read/write ratio. If most recipients open the feed, push wins — the writes were not wasted. If most events go to users who never look, pull wins — you avoided a huge write burst. Many real systems hybrid: push for the small, active fan-out and pull for the long tail.

Part 4

At-least-once, exactly-in-effect

A dropped notification is worse than a duplicated one, so the system over-delivers and then removes the duplicates. The guarantee is 'at least once' in transport and 'exactly once' in effect.

  1. 1
    Ack, then it is safe

    The broker does not consider an event delivered until a consumer acknowledges it. If a consumer dies before acking, the broker re-offers the event. That is what 'at-least-once' means: the event is presented at least once, possibly more.

  2. 2
    Retries create duplicates

    Because a consumer can die after doing the work but before acking, a retry redelivers an event that was already sent. Left alone, the user gets the notification twice. Retries are the mechanism that guarantees delivery and the cause of duplication at the same time.

  3. 3
    Dedupe makes it exactly-once in effect

    Every notification carries an id. Before sending, the consumer checks whether that id was already delivered to this recipient; if so, the duplicate is dropped. A bounded retry with back-off plus idempotent delivery is what turns at-least-once transport into exactly-once in effect.

Part 5

Route to the right channel

The same event may be push, email or SMS depending on the user and on urgency. The router reads the preference and the priority, and sends on the channel that matches both.

  1. 1
    One event, three possible doors

    A payment alert and a marketing digest are both 'events', but they want different doors. Urgent, personal things want push or SMS; bulk, non-urgent things want email. The router is where urgency and preference meet to pick the door.

  2. 2
    Preference is per user, per channel

    A user may have push on for security alerts and off for promotions, and email on for receipts and off for digests. The router consults that matrix, not a single on/off switch, so one user's settings can allow one channel and veto another for the very same event.

  3. 3
    Cost follows the channel

    SMS is billed per message and is expensive at scale; push is cheap; email sits in between. The router's channel choice is therefore also a cost decision — routing a bulk event to SMS would be correct for the user and ruinous for the budget, so priority and cost are weighed together.

★ Finale

End to end

One event, a whole crowd: it is published, buffered, fanned out, deduped and routed — landing on a phone, an inbox and a text for the recipients who opted into each.

  1. 1
    The full pipeline

    Every piece in one frame. The event is published to the broker, consumed and rendered, then fanned out and routed across push, email and SMS. The buffer sits between the spike and the channels so neither overwhelms the other.

  2. 2
    The fan-out spike, absorbed

    A viral event fires and touches a huge follower set all at once. The broker takes the spike, holds the backlog, and feeds the consumers at the rate the channels can serve. The spike is a queue depth, not an outage — that is the buffer earning its place.

  3. 3
    Deduped, then routed

    A consumer that was slow is retried and would have re-sent a notification already delivered. The dedupe check on the notification id drops the duplicate, and the original is routed to the channels each recipient opted into — push for the urgent ones, email for the rest.

  4. 4
    Landed, exactly once

    The notification reaches the recipients who opted in, on the channels they chose, and is delivered exactly once in effect despite the retries underneath. The pipeline did its job: a burst in, a calm, correct, deduped delivery out.

🌐 In the wild

In the wild

High-fan-out notification is one of the most deployed patterns in consumer software. The boxes below are anchored to the classes of well-known systems that run each piece — an illustrative mapping, not a claim about any one product's internals.

  1. 1
    The pattern, piece by piece

    Each box is a standard, named building block. Anchoring them to the classes of production systems that run that piece turns the abstract pipeline into 'the shape that pushes a huge share of the notifications on your phone'.

  2. 2
    Why the same pipeline keeps winning

    Independent products converge on the same pipeline because each piece removes a real failure: the broker removes the burst, the fan-out choice removes the write explosion, dedupe removes the double-send, and the preference gate removes the unwanted-and-expensive send. That convergence is the evidence the design is load-bearing.