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
Send a login code
Send a campaign
Receipts and bounces
A worker crashes
A provider goes down
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
The numbers, at a glance
23,000/sAverage
70,000/sDaily peak
300,000/sCampaign
1 call100 messages
75% push15% inbox, 9% email, 1% SMS
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.
POST
wait 200 ms on provider
200
+ Simple.− 500 sends/s a server; slow providers slow everyone.
code50M offers
one queue
code sent minutes later
+ Off the request path.− Codes wait behind campaigns.
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.
Producers
API server
User DBProviders
Producers
Load balancerAPI × N
Channel queuesWorkers
User DBProvidersDelivery log
Producers
Load balancerAPI × NPreference cache
Channel queuesWorkers, batched
User DBProvidersLog × 32 shards
ProducersCampaign fan-out
Load balancerAPI × NPreference cacheDedupe store
Priority + bulk lanesWorkers, batched
User DBProvidersLog × 32 shards
Was this walkthrough useful?Your vote tells us what to improve next.