Load/Bearing
High-level design · 14 of 22

Notification service

Deliver each message once, on the right channel, at the right time, even though every provider and network in the path can fail.

3 min readUsed in: 9 · Retry Storm

Every product grows a notification system: order updates by push, receipts by email, one-time passwords by SMS. Dozens of services want to notify users, so it pays to build one shared service that handles preferences, templates, retries and provider quirks in one place.

SERVICESorder, auth, socialNOTIFY APIvalidate + dedupeEVENT LOGKafkaROUTERprefs, templatesPUSH QAPNs / FCMEMAIL QSES / SendGridSMS QTwilio
Producers call one API. A router applies preferences and templates, then each channel has its own queue and workers.

The pipeline

  1. API: producers send an event, not a finished message: "order 812 shipped for user 42", with an idempotency key. The API stores the key and rejects repeats.
  2. Durable log: accepted events go to Kafka, so a slow provider never blocks the services calling the API.
  3. Router: loads the user's preferences and contact details, chooses channels, renders templates, and applies quiet hours and frequency caps.
  4. Channel queues and workers: one queue per channel, so a slow SMS provider can't delay push notifications. Workers call providers within each provider's rate limits.
  5. Status store: one record per notification and channel attempt: queued, sent, delivered, opened, failed.

Give one-time passwords and security alerts their own high-priority queue. Marketing can wait; a login code can't.

Deduplicating across channels

Duplicates come from two places: producers sending the same event twice, and the router choosing several channels for one event.

Retries without double notifying

The 10-million-follower broadcast

"Notify everyone who follows this account" must not become one request with 10 million recipients. A broadcast job pages through followers in batches of a few thousand and enqueues those batches at a rate the providers allow, often spread over minutes. Low-priority queues absorb it without delaying transactional messages. Collapse repeated broadcasts ("12 people liked your post") rather than sending one notification each.

Preferences and the law

Every channel needs per-category opt-outs, an unsubscribe link in marketing email, quiet hours in the user's time zone, and a cap on messages per day. These belong in the router, so no producing service can bypass them.

Interview checklist

Practise it

Level 9: Retry Storm

Put this into practice against live traffic. Your progress in the game is saved in your browser.

Play level 9

Further reading