Skip to content
SD-24 · Back to the write-up

Design a Notification Service

Check settings and dedupe once, queue by channel and priority, and let workers send in batches within each provider’s limits.

Follow a request

Producers
Accept
Queue + send
Providers + data
ServiceSingle sends
Campaign fan-outPages a segment
Notification APIRules + render
Dedupe storeKeys, 24 h
Preference cacheSettings + tokens
Channel queuesPriority + bulk
WorkersBatch, retry
ProvidersPush, email, SMS
UserPhone or inbox
Delivery logStatus + inbox
1service → api · POST /notificationsThe login service asks for a code to Ana by push, then SMS, with an idempotency key.1 / 8

The numbers, at a glance

Campaigns set the peakSends a second
For every 100 sends……one provider call when batched
1 call100 messages
Most sends are push2 billion a day by channel
So push provider limits shape the design, and SMS cost shapes the abuse rules.

A login code, in order

The API answers at step 5. Steps 6 to 10 happen on the priority lane, within about a second.

Service
Notification API
Dedupe store
Preference cache
Channel queue
Worker
Provider
1 POST + Idempotency-Key
2 SET idem NX
3 settings + tokens
4 push.priority
5 202 accepted
6 take, priority first
7 SET sent NX
8 send
9 accepted, msg id
10 receipt: delivered
RequestResponseAsync, does not block

How to split the queues

The decision this question is really about.

Send in the request
Breaks early
POST
wait 200 ms on provider
200
+ Simple.− 500 sends/s a server; slow providers slow everyone.
One shared queue
Head-of-line
code50M offers
one queue
code sent minutes later
+ Off the request path.− Codes wait behind campaigns.
Per channel + priority
Our pick
code50M offers
push.prioritypush.bulk
code in 1 sbatched, paced
+ Codes first; providers isolated.− 8 queues to run.

How it grows

Add a box only when a number forces you to. Highlighted boxes are new at each stage.

Stage 1 · ≈ 500 sends/sMake it work
Producers
API server
User DBProviders
One server sends inside the request.
Stage 2 · ≈ 5,000 sends/sQueue by channel
Producers
Load balancerAPI × N
Channel queuesWorkers
User DBProvidersDelivery log
Accept, queue per channel, send from workers, log statuses.
Stage 3 · ≈ 300,000 sends/sScale delivery
Producers
Load balancerAPI × NPreference cache
Channel queuesWorkers, batched
User DBProvidersLog × 32 shards
Cache settings, batch provider calls, shard the log.
Stage 4 · 300,000 sends/s, codes firstRight message, right time
ProducersCampaign fan-out
Load balancerAPI × NPreference cacheDedupe store
Priority + bulk lanesWorkers, batched
User DBProvidersLog × 32 shards
Priority lanes, dedupe keys and paced campaign fan-out.
Was this walkthrough useful?Your vote tells us what to improve next.