Design a Distributed Notification Service
Design a service that sends push messages, text messages and emails, at very large scale, without losing any.
Think of a notification service like a central post office. It takes one announcement and fans it out across several couriers: Push, SMS trucks, and Email carriers. Users get alerted on whichever device they use.
- Clients
- Your service
- Entry
- API gateway
- Services
- Notification service
- Channel workers
- Queues, caches
- Message queues
- Dead letter queue
- Data, outside
- Preferences database
- Providers
1. Requirements and scope
- Deliver push notifications (iOS APNS, Android FCM), SMS (Twilio), and Emails (SendGrid).
- Support user notification preferences and opt-outs.
- Provide delivery status tracking and retries.
- Guaranteed at-least-once delivery.
- Low latency for transactional alerts (<5s).
- Prioritization (OTP alerts bypass promotional blasts).
2. Back-of-the-envelope numbers
- Writes: 120 notifications a second, on average (6%)
- Reads: 2,000 status checks a second (94%)
Read-heavy: about 17 reads for each write. A cache and extra read copies help most here.
3. API
4. Data model and storage
NOTIFICATION_LOG: (id, user_id, channel, status, retry_count, created_at, delivered_at)
5. The design, in three versions
Version 1: Synchronous Direct Dispatcher
The app server calls the sending companies, such as Twilio and SendGrid, and waits for each answer.
Distributed Notification Service: Version 1: Synchronous Direct Dispatcher Version 1 of 3
The picture follows one request through the parts of this version, in order. Under it, switch a part off to see what the request does without it.
One request, step by step
Each numbered arrow is one step. Press "Simulate Request Flow" to follow them one at a time.
- The order of the steps
- A request or its reply
The parts: switch one off
1. Clients
2. Services
3. Data, outside
The steps in words0 of 3 steps shown
Your service to Notification service
A service asks to notify user 42.
Notification service to Providers
The app calls the provider and waits for it.
Notification service to Your service
It answers only after the provider replies.
Write path, read path and failures
Each path follows one request through the final design (version 3), one hop at a time.
Write pathSend a notification
- Your service
- Gateway
- Kafka topic
- Preference evaluator
- Dispatch workers
- Provider
- Event log
Your service to Gateway
A service calls POST /api/v1/notifications/send for user 42, with a template and an idempotency key.
Gateway to Kafka topic
The gateway checks the caller and writes the request to Kafka, grouped by user id. It answers "accepted" at once.
Kafka topic to Preference evaluator
A worker reads the message and checks what user 42 allows. A marketing message to a user who opted out is dropped here.
Preference evaluator to Dispatch workers
The message goes to the worker pool for its channel: push, SMS or email.
Dispatch workers to Provider
A worker checks the idempotency key, then calls the provider. A token bucket keeps it under the provider's rate limit.
Dispatch workers to Event log
The worker records the result: sent, failed or retrying.
Read pathCheck the delivery status
- Your service
- Gateway
- Notification API
- Event log
Your service to Gateway
The caller sends GET /api/v1/notifications/{id}/status.
Gateway to Notification API
The gateway checks the caller and passes the request on.
Notification API to Event log
The API reads the latest status for that id from the event log.
Notification API to Your service
It returns the status, such as "delivered at 12:00:05".
What breaks, and what happens then
A provider, such as the SMS vendor, is down
- What users see
- Messages on that channel are late. Other channels are not affected.
- What the design does
- Workers retry with growing waits. After several failures the message moves to the dead letter queue for review.
A worker crashes after calling the provider but before recording it
- What users see
- Kafka delivers the message again to another worker.
- What the design does
- The idempotency key is already stored, so the second worker skips the send. The user gets one message.
A marketing campaign floods the queue
- What users see
- Login codes could wait behind millions of promotions.
- What the design does
- Urgent and normal messages use separate topics and workers, so codes never queue behind campaigns.
6. Deep dives
7. Follow-up questions
- How do you handle users who opt out of marketing but must receive security OTPs? (Answer: Strict separation of Transactional vs Promotional pipelines with separate priority queues).
What it costs
The provider fees are the largest part: each text message costs money, while push messages are free to send. Your own servers are small next to that. Send by push first, and use a text only when the message is urgent.
Another way to design it
At low volume, a job table in your database and a few workers can replace Kafka. It is one less system to run. It stops being enough when a campaign sends millions of messages in minutes.
8. How answers are judged
A passing answer at Mid level. A complete design with numbers: about 120 notifications a second on average, bursting to 5,000 at peak during a campaign. It explains at-least-once delivery and goes deep on one part, such as duplicate sends.
| What is judged | Junior | Mid | Senior | Staff |
|---|---|---|---|---|
| BreadthHow much of the system does the answer cover? | Names the core parts: clients, servers, a database and a cache. | Covers the whole main flow, from the request to the stored data and back. | Builds a complete design without being led through it. | Covers the system, the systems around it and who owns each part. |
| DepthHow far does it go into the hard parts? | Explains what each part does and why it is there. | Goes deep on one part, such as the database or the cache. | Goes deep on the two or three riskiest parts. | Goes deepest where the risk is largest, and explains why the risk is there. |
| DrivingWho leads the conversation? | Follows the interviewer, step by step. | Moves forward alone, with an occasional nudge. | Leads the conversation from start to finish. | Changes the problem when the question asked is not the right one. |
| Trade-offsAre choices compared and justified? | Names more than one option. | Says why one option was picked over another. | Compares options in detail, with what each one costs. | Ties each choice to cost, speed and risk for the business. |
| Unclear questionsWhat happens when the question is vague? | Answers the questions that are asked. | Asks questions to make the problem clear. | Sets the scope and says what is left out. | Questions the assumptions behind the problem itself. |
| ScopeWhat does it consider beyond the normal path? | Covers the normal path, when everything works. | Adds what happens when a part fails. | Adds growth: what breaks at ten times the load, and the fix. | Adds abuse, cost and the daily work of running the system. |
Requirements and scope
Before I design, I want to check the scope. Notifications go out over push, SMS and email, and users can opt out. Should a security code bypass a promotional blast queue? I will assume at-least-once delivery, and that transactional alerts must arrive in under 5 seconds.
Users get notified over push, SMS or email depending on their device. Every notification goes out through the same pipeline, in the order it was sent.
Shows: Unclear questionsThe difference: Treating a security code the same as a promotional blast can delay it behind bulk sends. The strong answer asks about that split before designing.
Estimates
10 million notifications a day is about 116 a second on average, which I would round to about 120. Campaigns burst to the stated peak of 5,000 a second, about 40 times the average, so the write path needs a queue to absorb it. At 500 bytes each, a year of logs is about 1.8 TB.
10 million notifications a day at 500 bytes each is about 5 GB. Storage is small, so one server will hold it for a long time.
Shows: DepthThe difference: Five GB covers one day only; the weak answer never multiplies by the year the service runs, which comes to about 1.8 TB.
Core design
Templates and preferences sit in Postgres, since they change rarely and are looked up by user. The delivery log is only written and read by notification ID, and it grows by about 1.8 TB a year. So it gets its own store keyed by that ID, dropping rows after, say, 90 days: Cassandra with a time-to-live, or monthly Postgres partitions.
I would store every notification attempt as a row in one Postgres table, with an index on user ID. I would keep every row for good as delivery history.
Shows: DepthThe difference: The weak answer never removes old rows. At about 1.8 TB a year, the table and its index grow without limit, so storage and backups cost more every year.
Deep dive
The hard part is duplicate sends: a vendor can drop its acknowledgment, so a retry might send the same OTP twice. I would build an idempotency key from the user, template and a time bucket. I would save it in Redis before sending, and skip the send if the key is already there.
If sending fails or times out, I would keep retrying the vendor call until it succeeds, so the user always gets their notification.
Shows: DepthThe difference: Retrying without an idempotency key can deliver the same OTP or charge twice, since a lost acknowledgment looks like a lost send. The strong answer checks for that.
Failures and trade-offs
If a push notification fails, I would fall back to SMS only for high-priority transactional alerts, such as an OTP, after a short timeout. SMS costs far more per message than push, so using it for every failed promotional send would be too costly at 5,000 a second.
If a push notification fails, I would send it again by SMS. I would do that for every notification that fails.
Shows: Trade-offsThe difference: SMS costs more per message than push. Falling back for every failed send, including bulk promotions, is costly at thousands a second. The strong answer limits it to high-priority alerts.
We wrote this guide in our own words, informed by public interview guides such as AlgoMaster and Hello Interview. We are not connected to either site. Interviewers differ. The guide and the example answers show the direction each level takes, not a checklist.
10. Check your design with your own AI
Write your design first. Then copy this prompt into the AI chat you already use, and add your design at the end. It asks for a score in each area, one fix for each, and two follow-up questions.
The site sends nothing anywhere. An AI review can be wrong, so check what it says against sections 8 and 9.
See the prompt
You are a system design interviewer. Review my design for the interview problem below. Problem: Design a Distributed Notification Service Design a service that sends push messages, text messages and emails, at very large scale, without losing any. What users must be able to do: - Deliver push notifications (iOS APNS, Android FCM), SMS (Twilio), and Emails (SendGrid). - Support user notification preferences and opt-outs. - Provide delivery status tracking and retries. How well it must work: - Guaranteed at-least-once delivery. - Low latency for transactional alerts (<5s). - Prioritization (OTP alerts bypass promotional blasts). Numbers to assume: - 10 million notifications a day, with peaks of 5,000 a second during a campaign. Judge my design at the Mid level. A passing answer at this level: A complete design with numbers: about 120 notifications a second on average, bursting to 5,000 at peak during a campaign. It explains at-least-once delivery and goes deep on one part, such as duplicate sends. For each area below, say whether my design is strong, fine or weak. Give one reason and one fix for each: 1. Requirements and scope 2. Estimates 3. Core design 4. Deep dive 5. Failures and trade-offs Then ask me the two follow-up questions an interviewer would ask next. Do not write a full model answer for me. My design: [Describe your parts, how one request moves through them, and why you chose each one.]