Design a notification service
medium 45 minOne service that every team calls to reach a user by push, email, SMS or inside the app.
Video lesson · Chapter 1 of 5
An order ships and the phone should know
Theory
Read or listen first. About 2 min.
What it is
A notification service takes a request such as "tell this user that the order has shipped" and gets the message to the user: as a push message on a phone, an email, an SMS, or a message inside the app.
It sits between many producers (orders, sign-in, payments, marketing) and several outside providers. It does not own the last step. Apple, Google, email hosts and phone carriers do, so the design is mostly about waiting lines, rules and failures.
Why it exists
Without it, every team writes its own provider code, its own retry loop and its own opt-out list. One team forgets the opt-out list, and the company breaks a promise or a law.
With it, a producer says what happened and who should know. One place decides the channel, the words, the time of day and what to do when a provider is down.
A short history
1992
The first SMS is sent on 3 December and reads "Merry Christmas".
2003
The United States passes the CAN-SPAM Act. Opt-out requests for commercial email must be honoured within 10 business days.
2009
Apple launches the Apple Push Notification service (APNs) with iPhone OS 3 on 17 June.
2016
Google replaces Google Cloud Messaging with Firebase Cloud Messaging (FCM). RFC 8030 standardises web push in December.
2017
RFC 8058 defines one-click unsubscribe for email with an HTTPS POST.
Words to know
- Channel
- A way to reach a person: push, email, SMS, in-app.
- Provider
- The outside company that delivers on a channel, such as APNs or an email service.
- Device token
- The address of one app on one device. It can stop working at any time.
- Priority lane
- A separate waiting line, with its own workers, for one level of urgency.
- Quiet hours
- The hours in which a user does not want to be disturbed, in the user's own time zone.
- Idempotency key
- A name for a request, so that a repeat is recognised.
- Dead letter queue
- Where messages go after the last attempt, for a person to look at.
Solve it like an interview
New to it? Start with Approach. Revising? Go straight to the mock.
- 1ApproachWhat this question tests, where it gets hard, and how to spend the time.
- 2ScopeAsk what changes the design, then commit to a short list.
- 3NumbersWork out a number when the answer changes what you build.
- 4API and dataThe contract first, then the data that serves it.
- 5DesignStart with the smallest system that works. Change it only when something breaks.
- 6Deep divesCompare the options before you open them, then say which you would pick.
- 7Explain your choicesAnswer first. Then compare your reasoning.
- 8By levelThe same question is judged differently for mid, senior and staff.
- 9MockAnswer against the clock, then score yourself.
How it works
Step through the idea, or press Play.
Accept. A producer posts a request and gets 202 with an id
Understand it
The ringer knows the families, the hour and how serious the news is. That is the whole service.
Scope
What are we building?
A notification service carries timely messages to users over several channels. You meet one when a ride is on its way, a parcel has left, or a bank sends a one-time code.
Critical
"Your code is 000000, valid for 5 minutes." Security alerts and password resets.
High
"Your order 12345 has been shipped." Receipts and confirmations.
Normal
"Sam liked your photo." Likes, comments, follows.
Low
"50% off this weekend." Promotions, newsletters, digests.
Channels
| Channel | Reaches | Through | Watch out for |
|---|---|---|---|
| Push | Phones, browsers | APNs, FCM, Web Push | Tokens die; 4 KB payload limit at APNs |
| Inbox | An email service | Reputation, bounces, unsubscribe | |
| SMS | Any phone | A carrier gateway | Price per message, slow rate per number |
| In-app | Open app | Our WebSocket servers | Nothing arrives if the app is closed |
| Webhook | Another system | HTTPS call | The receiver may be down |
Similar products
| Product | Known for |
|---|---|
| Firebase Cloud Messaging | Google's push service |
| Amazon SNS | Publish and subscribe, push and SMS |
| OneSignal | Push for many platforms |
| Twilio | SMS, voice and messaging APIs |
| SendGrid | Email delivery |
| Braze | Customer engagement campaigns |
The hard part
Urgent and bulk share the same road
Averages are easy here. The test is the moment when ten million adverts are waiting and one person is looking at a sign-in screen. That code must overtake all of them, in the API, in the queue, in the workers and in the provider's quota.
The finished system
Where the design ends up
This is the last version. The Design tab starts with one service and one database.
The whole system
Where to read more
Ideas this problem borrows
| Idea | Its home | Used here for |
|---|---|---|
| Waiting lines | Queues, log-based queues | Lanes by channel and priority |
| One event, many readers | Publish and subscribe, fan-out | Campaigns, status events |
| Safe repeats | Idempotency, retries | Claims before sends |
| Outside failures | Circuit breaker, fallbacks | Backup providers |
| Speed limits | Rate limiter | Provider quotas, user caps |
| Live messages | Real-time APIs, webhooks | In-app and feedback |
| Later, at 9 in the morning | Task scheduler | Quiet hours, scheduled sends |
Interview tabs: approach, scope, numbers, API and data, design, deep dives and mock.
Summary
The whole topic in one minute.
A notification service accepts quickly, then delivers slowly. The API checks the request, writes it to a durable queue and answers 202. Workers do the rest, one pool for each channel, so a slow email provider cannot hold up push.
Urgency gets its own lane all the way to the provider. Preferences are checked twice. Each send is claimed before it is made, so retries rarely become duplicates. What the providers report comes back as events, and it is reported honestly: accepted is not the same as seen.
- Answer 202 only after the request is safely in a replicated log.
- A lane for each channel and priority, with workers reserved for the critical ones.
- Check preferences when the message is accepted and again just before it is sent.
- Claim a send before making it. Duplicates become rare, never impossible.
- A message has a deadline. Retrying a five-minute code for hours is worse than failing.
- Accepted by the provider is not delivered, and delivered is not read.
Sources
- Apple: sending notification requests to APNs
- Apple: handling notification responses from APNs
- Firebase: throttling and quotas
- Firebase: manage registration tokens
- RFC 8058: one-click unsubscribe
- Google: email sender guidelines
- Amazon SES: account-level suppression list
- Apple: Protect Mail Activity
- Kafka consumer: pause and resume
- United States Code, 15 USC 7704 (CAN-SPAM)