System Design: Notification System (Walnut Notify: Push, In-App, Email and Text Messages for Every App)
We design a notification system for a company with many apps. Our version is called Walnut Notify. Every Walnut app sends through it: the Walnut store, Walnut News, the Walnut Feed social app and the accounts team.
A notification reaches a person on one or more channels. A channel is a push on the phone or the browser, an item in the app's inbox, an email or a text message. Walnut Notify picks the channels, follows each person's settings, and talks to the outside companies that deliver each one.
As in any system design interview, every number here is our own planning assumption, and the design is our own. All times are US Central time unless a line says otherwise.
How to read this post. It takes about 65 minutes in full, so it is built to be read in parts:
1. Requirements
1.1 What we are building
Walnut Notify does four jobs:
- It takes a request once. Another team's service says "tell user 4417 that order ord_51m8 is confirmed". A retry of the same request is not a second notification.
- It decides how to tell the person. It finds their phones and browsers, reads their settings, and picks the channels.
- It delivers through outside companies. Apple delivers to iPhones and Google to Android phones. The browser makers deliver to browsers. An email company and a text message company do the rest. Each one limits how fast we may send, and each one sometimes fails.
- It keeps the urgent apart from the many. A sign-in code must arrive in seconds. It must do so even while 40 million marketing pushes wait to go.
The story takes place on Friday 27 November 2026, Black Friday:
- 08:45:00. Walnut Flash Sale sends "Doors open at 9:00" to 40 million people who turned on deal alerts. It must go out within 5 minutes, and it expires at 09:00.
- 08:45:00. Noah in Seattle is skipped. It is 06:45 there, inside his quiet hours until 08:00. His copy would wait until 10:00 Central, after it expires.
- 08:45:20. Emma in Chicago signs in on a new laptop. Her sign-in code goes by text message and reaches her phone in 2 seconds, while millions of campaign pushes are still queued.
- 09:02. Maria pays for a console in the flash sale. "Order confirmed" reaches her iPhone and her open laptop tab, and the receipt reaches her email. Her old Android phone's token is dead, so Google refuses it, and we remove it.
- 10:14. Apple's push service fails for 6 minutes. iPhone pushes wait and retry, and all of them are sent by 10:23. Sign-in codes keep going by text message.
- 11:30. Walnut News sends a breaking story to the 30 million followers of Top Stories. The last one leaves at 11:32.
- 12:00. Kai in Honolulu gets the story at 08:00 his time, when his quiet hours end.
- 12:00 to 12:10. Olivia's review gets 12 likes. At 12:10 she gets one push: "Liam and 11 others liked your review."
- 14:00. A gateway machine that holds 200,000 open app connections crashes. The apps reconnect within 30 seconds, and their inboxes lose nothing.
- 15:00. Grace in New York is due a fourth deal alert today. Her cap is 3, so it is skipped.
- 18:00. Ava taps "Unsubscribe" in a deals email. Her next deals email is stopped within seconds.
The hard part is sending the right message to the right devices once and on time. The urgent few must get through while millions of others wait, and the outside companies limit and sometimes refuse what we send.
1.2 Words we use
Words used in only one place are explained there. Each word below is used all through the post.
The message
| Word | Meaning |
|---|---|
| Notification | One message for one person, such as "Order confirmed". It may go out on several channels. |
| Sender | Another team's service that asks Walnut Notify to send, such as the Order service. |
| Channel | A way to reach a person: push, in-app inbox, email or text message. |
| Category | The kind of message, such as "orders", "deals" or "sign-in". People turn categories on and off. |
| Lane | How urgent a notification is. Critical is sign-in codes and security alerts. Transactional is orders, rides and messages. Bulk is campaigns, news and social activity. |
| Template | The text of a notification with blanks, such as "Order {order} is confirmed", in each language. |
| TTL | Time to live: when a notification stops being worth sending. "Doors open at 9:00" is worthless at 09:00. |
Reaching devices
| Word | Meaning |
|---|---|
| Push | A message shown on the phone or the browser even when the app is closed. |
| Device token | The address of one app on one phone or browser, given by Apple, Google or the browser. A new install gets a new token. |
| APNs | Apple Push Notification service. It delivers pushes to iPhones, iPads and Macs. |
| FCM | Firebase Cloud Messaging, Google's service that delivers pushes to Android phones. |
| Web push | A push to a browser, through that browser maker's push service. It works with the tab closed. |
| Provider | An outside company that delivers one channel: Apple, Google, a browser maker, the email company or the text message company. |
| Quota | The most messages a provider accepts from us per minute. Above it, the provider refuses. |
| Inbox | The list of notifications inside the app, with read and unread marks. |
| Live connection | An open connection from an app or tab to our Gateway, so a new inbox item appears at once. |
| Gateway | Our servers that hold live connections. |
| Collapse ID | A label on a push. A second push with the same label replaces the first on the screen, so a repeat does not show twice. |
People's settings
| Word | Meaning |
|---|---|
| Quiet hours | Hours when a person gets no bulk notifications, 22:00 to 08:00 in their own time zone by default. |
| Cap | The most bulk notifications a person gets in a day, such as 3 deal alerts. |
| Digest | Many small events sent as one notification, such as 12 likes in one push. |
| Suppression list | Email addresses and phone numbers we must never send to again, because they bounced, complained or unsubscribed. |
Systems
| Word | Meaning |
|---|---|
| Kafka | A log that keeps messages in order, split into partitions, until readers take them. Readers can read again from any point. |
| PostgreSQL | A relational database with transactions. |
| Cassandra | A database that spreads rows over many machines by a key and keeps 3 copies of each. It is built for many writes. |
| Valkey | An in-memory key-value store, an open-source fork of Redis. A Lua script runs inside it as one step. |
| ClickHouse | A database that stores data by column, built for counting billions of rows. |
| Idempotency key | A unique key the sender puts on a request, so a retry is done once. |
| p99 | The time that 99 of every 100 requests beat. |
IDs in this post
Every ID below is made up for the story.
| ID | What it names | Example |
|---|---|---|
| user 4417 | A person's user ID | Maria |
| user 2207 | A person's user ID | Emma |
| ord_51m8 | An order ID in the Walnut store | Maria's console |
| n_f025c34b | A notification ID | Maria's "Order confirmed" |
| campaign bf26-doors | A campaign ID | "Doors open at 9:00" |
| topic top-stories | A Walnut News topic | 30 million followers |
| gw-31 | One Gateway machine | Emma's phone is connected to it |
1.3 Every kind of request and change
The story follows a few people. Walnut Notify handles much more than that. Each row names the part that handles it.
| Kind | What it is | How big or how often | Which part handles it | Outside party that takes part |
|---|---|---|---|---|
| One person, transactional | Order confirmed, driver arriving, new message | About 15,000 a second at peak | The Notify API, then the Router | Apple, Google, the email company |
| Sign-in code or security alert | A code or "new sign-in from Chicago" | About 350 a second at peak | The critical lane | The text message company, Apple, Google |
| Campaign | One message to a list of people chosen by a team | 40 million in 5 minutes | The Campaign service and the Audience expander | Apple, Google, the email company |
| Topic | A message to everyone who follows a topic | 30 million in 2 minutes | The Audience expander | Apple, Google, the browser makers |
| Social activity | A like, a comment, a new follower | 5,000 a second, mostly sent as digests | The Digest job | Apple, Google |
| Scheduled | "Your ride is in 1 hour", or a send held for quiet hours | About 600 a second | The Scheduler job | None |
| Inbox | Read the inbox, mark items read, count unread | About 40,000 reads a second | The Inbox service | None |
| Live update | A new inbox item shown at once in an open app | Up to 20 million open apps and tabs | The Live service and the Gateways | None |
| Device registration | An app reports its token on start | About 5,000 a second | The Notify API | Apple, Google and the browsers give the tokens |
| Settings and unsubscribe | Turn a category off, set quiet hours, one-click unsubscribe | About 300 a second | The Notify API and the Feedback service | The email company passes on unsubscribes |
| Provider feedback | Dead tokens, email bounces, spam complaints, delivery reports | About 20,000 a second | The senders and the Feedback service | Every provider |
| Status and reports | "Was it delivered?" and campaign results | A few hundred a second | ClickHouse | None |
This post follows Maria's order and Emma's code in depth. It also follows the campaign, the breaking story and Olivia's digest. The other kinds use the same parts.
1.4 Functional requirements
- Send to one person. A sender names a user, a template, its data and a category. A retry with the same idempotency key is sent once.
- Every channel. Push to phones and browsers. An in-app inbox. Email and text message.
- Pick channels by the person's settings. Each person turns categories and channels on and off. Unsubscribed and bounced addresses are never used.
- Urgent first. A sign-in code or a security alert goes ahead of everything else.
- Send to millions. A campaign to a list of people, or a message to every follower of a topic.
- Send later. At a set time, at a set local time for each person, or after their quiet hours.
- Do not flood people. Daily caps on bulk notifications, and digests for small repeated events.
- Keep device tokens current. Add new tokens, and remove tokens a provider says are dead.
- Inbox. Show each person their notifications, with read marks that agree on all their devices.
- Status. Show whether each notification was sent, delivered and opened, and each campaign's results.
Out of scope:
- writing the messages and choosing the audience, which the sending teams do;
- the apps' own screens, which only show what we send;
- how Apple, Google and the other providers deliver inside their own networks.
1.5 Non-functional requirements
- Urgent is fast. A sign-in code reaches its provider within 2 seconds at p99, even during the biggest campaign.
- Transactional is fast. An order or ride notification reaches its provider within 5 seconds at p99.
- Bulk is on time. 40 million campaign messages in 5 minutes. 30 million topic messages in 2 minutes.
- Nothing accepted is lost. Once the API answers 202, the notification is sent before its TTL or reported as failed. A rare repeat is allowed, and its collapse ID hides it on the screen.
- Polite to providers. We never send faster than a provider's quota. Every rule of the email and text message companies is followed.
- Survives failures. A provider outage delays notifications. It never drops one that has not expired.
1.6 The numbers
These are rough sums, the kind a candidate does at a whiteboard in a few minutes.
| Number | How we get it | Result | What it decides |
|---|---|---|---|
| Notifications a day | 80 million daily users × 25 each, across all apps | 2 billion a day, about 23,000 a second | The average is easy. The peaks decide the design |
| Campaign peak | 40 million ÷ 300 seconds | About 133,000 a second | Expand the audience in batches, and send from many workers in parallel |
| Topic peak | 30 million ÷ 120 seconds | 250,000 a second | The biggest peak. It must fit under the providers' quotas |
| Sign-in codes by text | 3 million a day × about 0.8 cents each | About $24,000 a day | Text messages only for codes and security alerts |
| Device tokens | 200 million users × 1.6 devices × 300 bytes | About 100 GB | Fits one PostgreSQL primary. Read 500 users per query |
| Live connections | 20 million open apps × 10 KB of memory each | 200 GB of Gateway memory | Many Gateway machines, so a registry must say which one holds each person |
| Inbox | 600 million inbox items a day × 500 bytes × 90 days | 27 TB, 81 TB with 3 copies | Cassandra, split by user, with a 90-day expiry |
| Delivery events | 2 billion × 3 events: sent, delivered, opened | 6 billion a day, about 70,000 a second | A log and a column store, not the main database |
What these numbers tell us: our own servers are not the hard part. The peaks of 133,000 and 250,000 a second must fit under the providers' quotas.
Meanwhile 350 sign-in codes a second must never wait behind them. The rest is storage that splits cleanly by user.