Sub topic 3
A high-level architecture
This chapter assumes you know how HTTP APIs work, what a message queue is, and the difference between a database and a key-value store. Here you will see how the pieces of a notification system fit together. Later chapters cover each piece in detail.
The core idea: decouple producers from delivery
Services such as orders, billing, and social features should not call push, SMS, or email providers directly. Provider calls are slow, they fail, and each provider has its own API. If producers called providers, every producer would inherit those problems.
Instead, producers send a small event to the notification system, and the system handles everything after that. An event says that something happened to a user, for example "order A-77 shipped for user-42".
The main components
Each stage has one job:
| Component | Responsibility |
|---|---|
| Ingestion API | Validates the event, assigns or checks its id, and acknowledges quickly |
| Router | Looks up user preferences, picks channels, and renders a template per channel |
| Channel queues | Buffer messages so a slow channel does not block the others |
| Channel workers | Take messages from a queue, call the provider, and handle retries |
| Providers | External services that actually reach the device or inbox |
| Delivery status store | Records what happened to each message |
Why one queue per channel
Channels behave differently. SMS is slow and expensive, and email can tolerate delay. Push is usually fast. With a separate queue and worker pool for each channel, an outage at the SMS provider fills only the SMS queue. Push and email keep flowing. You can also scale each worker pool on its own.
Where reliability enters
Because the queue sits between acceptance and delivery, the system can retry failed sends without involving the producer. Retries create a new risk: the same message might be sent twice. Workers therefore need a deduplication check before each send. The chapters on retries and idempotency cover both.
A common mistake
Putting preference checks inside each producer. Preferences then get duplicated across services and drift apart. Keep them in one place, the router, so that opt-outs apply to every notification.
Exercise
The SMS provider goes down for an hour. In this architecture, what happens to push and email notifications, and why?
Show answer
They keep being delivered normally. Each channel has its own queue and worker pool, so SMS messages pile up only in the SMS queue, and the SMS workers retry. The other queues and workers are unaffected.
Exercise
Why does the ingestion API acknowledge the producer before the provider call finishes?
Show answer
Provider calls are slow and can fail. If the producer waited for them, its own latency and reliability would depend on the provider. Acknowledging after the event is safely queued keeps the producer fast, and the queue lets workers retry without the producer's involvement.