Design a Notification System
How to design a service that sends push, SMS and email notifications at scale, including queues, retries, duplicates, rate limits and provider outages.
On this page
A notification system is a shared service that other teams call to send a message to a user by push notification, SMS or email. The calling team says which user to notify and what about, and the service decides which channels to use, applies the user's preferences, and hands the message to a third-party provider for delivery. The steps below follow A Framework for Any Design.
The problem is hard because the system depends on providers that you do not control. A provider can time out without telling you whether the message was sent, a large marketing campaign can delay an urgent login code, and a retry can make a user receive the same message three times. Interviewers ask it to see how you handle queues, retries, duplicates and priorities.
Clarify the problem
Design a notification system.
I assume it is a shared service that other teams call, and that it sends push, SMS and email through third-party providers. Does it only send alerts triggered by events, or also marketing campaigns?
Both. A campaign can target 50 million users.
What are the daily volumes, and how quickly must a login code arrive?
There are about 500 million pushes, 100 million emails and 5 million texts a day across 100 million users. Login codes must arrive within seconds, even while a campaign is running.
Then priority is a core requirement, because campaigns and login codes share the same providers. I will aim for at-least-once delivery with deduplication, since a lost login code is worse than a duplicate one.
- Functional: send a templated notification by push, SMS or email; send campaigns to large user segments; let users choose channels per category; and let callers check the status of a notification.
- Non-functional: high-priority messages such as login codes and security alerts reach the provider within 5 seconds, even during a campaign. No accepted notification is silently dropped, and duplicates are rare. Accepting requests must be 99.99% available, while actual sending is allowed to lag.
- Out of scope: the in-app inbox, the tools for building campaign audiences, and A/B tests of message text.
Estimate the scale
- Average rates: 500 million pushes ÷ 86,400 seconds ≈ 5,800 a second, 100 million emails ≈ 1,160 a second, and 5 million texts ≈ 58 a second. The total is about 7,000 sends a second.
- Campaign peak: sending to 50 million users in 30 minutes means 50,000,000 ÷ 1,800 seconds ≈ 28,000 sends a second on one channel, which is four times the daily average.
- Provider limits: assume the SMS provider allows 500 texts a second, which is a hard ceiling.
If all push notifications share one first-in-first-out queue, how long does a login-code push wait behind a 50-million-user campaign that was queued just before it?
- 50 million campaign pushes already in the queue
- Senders drain the queue at 28,000 pushes a second
Show the working
- 50,000,000 ÷ 28,000 ≈ 1,800 seconds
- 1,800 seconds = 30 minutes
Estimate 30 minutes (anything from 10 minutes to 90 minutes is a good answer)
The login code expires long before it is sent.
Write the endpoint that a service uses to send one notification. What does it return, and how can the caller retry safely after a timeout?
Compare with a model answer
It is a POST with the user, template, parameters, priority and an idempotency key. It returns 202 Accepted with a notification id, and a status endpoint reports what happened later. A retry with the same key returns the same id instead of sending again.
Define the API Optional
Optional in the interview. Sketch the API only if the interviewer asks, if an API choice shapes the design, or if time permits. Otherwise say "I'll skip the detailed API unless you want it" and go to the data model.
POST /v1/notifications
Idempotency-Key: order-881-shipped
body: { "user_id": 42, "template": "order_shipped", "params": { "order": "881" },
"category": "order_updates", "priority": "high" | "normal" | "bulk",
"channels": ["push", "email"]?, "expires_in": "24h"? }
202 Accepted { "notification_id": "n_501" }
400 Bad Request unknown template or missing parameter
404 Not Found unknown user
409 Conflict same Idempotency-Key with a different body
429 Too Many Requests this caller is over its quota
GET /v1/notifications/n_501
200 { "push": "sent", "email": "retrying", "sms": "skipped: user opted out" }
PUT /v1/users/42/preferences { "order_updates": ["push", "email"], "marketing": [] }
POST /v1/campaigns { "segment": "...", "template": "...", "send_at": "..." } 202
POST /webhooks/{provider} delivery receipts and bounces from providersThe decision worth arguing is that the endpoint returns 202 and not 200. Providers can be slow or down for minutes, and the order service or the login flow should never have to wait for them. The Idempotency-Key header makes the caller's retries safe, as explained in Idempotency and Retries.
Which records do you need, which of them are read on every send, and what kind of store suits each?
Compare with a model answer
You need a notification log, written heavily and read by id, and small per-user records for preferences and device tokens, which are read on every send and should be cached. The access patterns differ, so the stores differ.
Model the data
notifications -- about 500 bytes, kept 90 days
notification_id CHAR(26) PRIMARY KEY
idempotency_key VARCHAR(100) UNIQUE (per caller), expires after 24 h
user_id BIGINT
template, params, category, priority, created_at, expires_at
deliveries -- one row per (notification, channel, device)
notification_id, channel, target -- target: device token, phone or email
status -- queued | sent | delivered | failed | skipped
attempts, provider, provider_msg_id, last_error, updated_at
preferences PRIMARY KEY (user_id) -- category -> allowed channels, quiet hours, time zone
devices PRIMARY KEY (user_id, device_token) -- platform, last_seenThe log takes thousands of writes a second, is read by id and expires after 90 days, so a key-value or wide-column store with a time to live fits well, such as DynamoDB or Cassandra. Preferences and devices are small, change rarely and are read on every send, so they belong in a relational database with a read-through cache in front. The idempotency key needs an atomic "insert if absent" operation, and both kinds of store provide one.
Sketch the path from a calling service to a phone, an inbox and a text message. Where do you check preferences, and where do the queues go?
Compare with a model answer
A thin API validates, deduplicates, logs and returns 202. A router applies preferences and templates and puts each message on its channel's queue, and each channel has its own senders and provider.
High-level design
The API must answer in milliseconds, so it only validates, records and enqueues. Each channel gets its own queue and senders, so a slow email provider never holds up push.
request and replyasynchronous message
1The order service calls
POST /v1/notificationsfor user 42 with the keyorder-881-shippedand normal priority.- rows for key
- 1
2The API inserts the key and the notification in one conditional write. The key is new, so the notification gets the id
n_501and is marked as queued.- rows for key
- 1
3The API puts
n_501on the intake queue and answers202.- rows for key
- 1
4The 202 response is lost on the network, so the order service retries with the same key. The insert finds the existing key and returns
n_501again, and nothing new is queued.- rows for key
- 1
5A router reads user 42's settings from the cache. The user wants order updates by push and email but not by SMS, and has two phones registered.
- jobs
- 3
6The router renders the templates and enqueues two push jobs, one for each phone, and one email job. SMS is recorded as skipped.
- jobs
- 3
- sent
- 2
7The push senders hand both messages to the platform push services and mark them as sent.
- jobs
- 3
- sent
- 2
- attempts
- 1
8The email sender times out after 5 seconds. It cannot tell whether the email was sent.
- jobs
- 3
- sent
- 3
- attempts
- 2
9The email sender retries after a backoff delay and reuses the same message id. A provider that honours the id will discard the copy if the first attempt had already gone through.
Deep dives
Queue layout: one queue, one per channel, or one per channel and priority
The queue layout decides whether one kind of traffic can delay another. With a single queue for everything, the slowest channel sets the pace for all the others, so an email outage or a large campaign delays every login code behind it. That is acceptable only for a prototype.
With one queue per channel, each channel scales and fails on its own, and a slow email provider no longer affects push. It does not solve priority, because inside the push queue a campaign still delays an urgent message by 30 minutes.
With one queue per channel and priority, urgent messages get their own queue and a reserved share of the senders, so they never wait behind bulk traffic. The cost is more queues, and bulk must be throttled so it does not use all of a provider's capacity. This is the choice whenever urgent and bulk messages are mixed.
| Option | Good at | Bad at | Pick it when |
|---|---|---|---|
| One queue for everything | There is one thing to run and watch. | An email outage or a campaign blocks every login code behind it. | Use it for a prototype with a single channel. |
| One queue per channel | Channels scale and fail independently. | Within a channel, a 50-million-user campaign still delays urgent messages by 30 minutes. | Use it when the system has no bulk traffic. |
| One queue per channel and priority Usual default | Urgent work has its own queue and reserved senders, so it never waits behind bulk. | There are more queues to run, and bulk must be throttled so that it does not starve other traffic. | Use it whenever urgent and bulk messages are mixed. This is my choice. |
request and replyasynchronous message
The fast queue is guaranteed a share of the senders and of each provider's rate limit, for example 20%, and bulk traffic uses the rest at a fixed pace below the provider's ceiling. Failed sends go to a separate delay queue so that a message that keeps failing never blocks the head of the main queue.
Retries and duplicate messages
Every queue in this design delivers at least once, as described in Message Queues and Streams. A sender can crash after the provider accepts a message but before it marks the job done, and then another sender repeats the job. Exactly-once delivery is not possible here, because the call to the provider and the write of the status do not share a transaction. What you can do is make duplicates rare, using four measures:
- Before sending, the sender checks the
deliveriesrow and skips the job if it already sayssent. This closes most of the window, but not all of it. - The sender includes a stable message id such as
n_501:emailin each call. Some providers discard repeated ids, and push platforms collapse notifications that share a collapse key. - The sender retries only errors that can succeed later, which are timeouts, 5xx responses and 429 responses. For an invalid device token or a hard email bounce, it removes the token or suppresses the address instead of retrying.
- Retries use exponential backoff with random jitter, for example 1, 2 and 4 seconds, capped at 10 minutes, until the message's deadline passes. After that the job goes to the dead-letter queue.
Intake has a similar gap. If the API crashes after writing the log but before enqueuing the message, the caller's retry finds the existing key and stops, so the message would never be sent. A sweeper job re-enqueues any notification that is still marked queued after a minute, and the routers skip ids they have already routed.
Preferences and rate limits
The router checks a user's preferences as late as possible, just before it enqueues the message for a channel. A user who opts out at 09:15 must be skipped by a campaign that started at 09:00, which is only possible if the check happens at send time. Quiet hours delay normal messages until morning in the user's time zone, but high-priority messages are sent at once.
Three limits protect different things.
- Per user: a limit such as 3 marketing pushes a day protects users from spam. It is counted in the cache under a key like
42:marketing:2026-11-14. - Per caller: a quota for each API key stops a buggy service that is stuck in a loop from flooding users, and the API answers with 429 when the quota is exceeded.
- Per provider: a token bucket shared by all SMS senders keeps the system under the provider's limit of 500 texts a second. Rate Limiting describes how a token bucket works.
Provider failures and failover
A provider can fail in three ways: it can return errors, it can respond slowly, or it can accept a message and then never deliver it. Slowness is the most damaging of the three, because senders sit waiting and the queue grows. Each provider call therefore has a short timeout, and each provider has a circuit breaker that stops calls to it for a while when, for example, half of the calls in the last 30 seconds have failed.
There are three ways to respond. The first is to keep retrying the same provider, which needs no second integration but creates a long backlog in a long outage. It is the only option for push.
The second is to fail over to a second provider when the circuit breaker opens. This keeps SMS and email flowing through an outage, which matters most for login codes. The costs are a second integration to maintain and the chance of a duplicate, because a request that timed out may have been delivered. This is the choice for SMS and email.
The third is to split traffic across two providers all the time, which doubles the integration work and is worth it only when volume exceeds one provider's limits.
| Option | Good at | Bad at | Pick it when |
|---|---|---|---|
| Retry the same provider | It is simple and needs no second integration. | A long outage creates a long backlog. | Use it for push, where each platform is the only route to its phones. |
| Fail over to a second provider Usual default | It keeps SMS and email flowing through an outage. | A request that timed out may already have gone out, so failover can duplicate it. It also needs a second integration. | Use it for SMS and email, especially login codes. This is my choice. |
| Split traffic across providers all the time | Both providers stay tested, and an outage halves capacity instead of stopping it. | The integration and monitoring work doubles. | Use it when volume is beyond what one provider allows. |
Silent loss, where a provider accepts a message and the user never receives it, is the hardest case to detect. You alert when the provider's delivery-receipt rate falls well below normal, and for login codes the app offers a "resend code" button.
Bottlenecks and failures
At ten times the campaign peak, campaigns need about 280,000 sends a second. Routers and senders are stateless, so you add more of them. The first limit reached is the providers' rate limits, handled with several provider accounts and longer campaign windows. The next is the preference cache, which you scale with replicas.
| When this fails | What happens | What you do |
|---|---|---|
| The API | Callers receive errors or timeouts. | Callers retry with the same idempotency key, and you run several API instances behind a load balancer. |
| A router or sender | Its jobs are not acknowledged. | The queue hands them to another worker after a timeout, and the sent check limits duplicates. |
| The preference cache | Routers cannot check preferences. | Routers fall back to the database at a limited rate, and bulk sends are paused so that opt-outs are never ignored. |
| An SMS or email provider | Sends fail or hang. | The circuit breaker opens and traffic fails over to the second provider, with high priority first. |
| A platform push service | Push jobs back up in their queue. | Senders retry with backoff until each job's deadline, because push has no second route. |
What a strong answer sounds like
| Level | What the answer does |
|---|---|
| Junior | The API calls the providers directly and there is a preferences database. The candidate adds a queue only after being asked about slow providers. |
| Mid-level | The API returns 202 and the design uses a queue for each channel. The candidate checks preferences, retries with backoff and mentions idempotency keys. |
| Senior | The candidate finds the conflict between campaigns and login codes from the numbers and solves it with priority queues. They explain that duplicates can be made rare but not impossible, and plan for provider slowness and silent loss. |
The SMS provider times out on a login code. What do you do?
I cannot know whether the text was sent, so I retry, because a duplicate code is better than a missing one. If the circuit breaker is open, the retry goes to the second provider, which may mean the user gets two texts.
What about a marketing text?
A duplicate costs money and annoys the user, so I would retry only through the same provider with the same message id, and I would accept that a few messages are lost.
Follow-up questions
How do you send a campaign to 50 million users?
A campaign job reads the segment in pages and feeds the bulk queues at a fixed pace, which is 28,000 messages a second for 30 minutes. It saves its progress after each page, so it can resume from that point after a crash instead of starting over. For SMS the provider's ceiling of 500 texts a second means 50 million texts would take about 28 hours, so an SMS campaign is spread over a longer window or sent through several provider accounts.
How do you handle device tokens that stop working?
Platform push services report invalid tokens in their responses, for example when an app has been uninstalled. The sender deletes such a token immediately.
A user gets the same alert from three services. How do you stop it?
The router can attach a group key to each alert and skip or merge an alert if one with the same key was already sent to that user in the last 10 minutes. The better fix is to give each kind of event a single owning service, so that only one service ever sends it.
How do you know whether a notification was delivered?
Providers report delivery receipts and bounces by calling the webhook endpoint, and each receipt carries the provider message id that the sender stored. The webhook handler finds the matching row in deliveries and updates its status. A push platform only confirms that it accepted the message, so for push the status cannot go beyond sent.
After your attempt, tick what you really did. Be strict: "I thought about it" is not "I said it out loud".