Mock design: notification system
We'll cover the following
- Visual summary
- Overview
- Say the hard part early
- Step 1: Clarify requirements
- Functional (ACTORS)
- Non-functional (SCALED)
- Step 2: Estimation
- Step 3: APIs and data model
- Step 4: High-level design
- Step 5: Deep dive on the hard parts
- 5a. Priority isolation
- 5b. Fan-out: "send to all 100M"
- 5c. Per-user checks before sending
- 5d. Retries, duplicates and the DLQ
- The four what-ifs, per box
- Step 6: Where it breaks at 10x
- Monitoring, next steps and trade-offs
- Summary
Visual summary

Download imageFree to share, please link back to this lesson.
Prompt: "Design a notification system that sends push, email and SMS to 100M users." This lesson follows the order from the Interview framework lesson: requirements (ACTORS, then SCALED), estimates, APIs and data model, boxes, deep dive, then where it breaks at 10x.
Say the hard part early
What makes this problem special is the mix. Huge marketing bursts share the system with tiny, urgent messages like OTPs, so priority isolation matters. Retries must never turn into duplicate sends, so dedupe matters. Say this out loud right after the requirements, and spend your deep dive here.
| Minutes | Step and what you produce |
|---|---|
| 0-7 | Requirements. Two columns on the board, an out-of-scope list, assumed numbers. |
| 7-12 | Estimation. Average and peak QPS, storage, provider cost. |
| 12-18 | APIs and data model. Endpoints, tables, one store per table. |
| 18-28 | High-level design. The boxes, one line each. |
| 28-40 | Deep dive. Priority queues, fan-out, dedupe, retries. |
| 40-45 | Bottlenecks at 10x. What breaks first, what to monitor. |
Step 1: Clarify requirements
State your assumptions with numbers first, then ask the questions in two columns: functional (ACTORS) and non-functional (SCALED).
Functional (ACTORS)
| Letter | Asked and agreed |
|---|---|
| Actors | Who uses it? Internal services (orders, payments, auth) trigger single messages. Marketers trigger campaigns. End users receive them and manage preferences. |
| Core flows | What must it do? (1) Send one message, such as an OTP or order alert. (2) Send a campaign to a segment, up to all 100M users. (3) Let a user set preferences and register devices. Most important: OTP latency and the campaign burst. |
| Triggers | How does work start? An API call from a service, a campaign created by a marketer (now or scheduled), or a schedule such as a daily digest at 9am local time. |
| Outputs | What comes back? A push, email or SMS on the user's device. The caller gets an id and a delivery status. Marketers get campaign stats. No real-time pull. |
| Rules | Which business rules? Opt-in per channel, a frequency cap per user per day, quiet hours by time zone, priority by type, and expiry (an OTP older than a few minutes is useless, so drop it). |
| Scope | What is in and out? In: three channels, templates, scheduling, retries, status tracking. Out (say it aloud): template editor UI, in-app inbox, A/B analysis, rich media. This is a new system, not a migration. |
Non-functional (SCALED)
| Letter | Asked and agreed |
|---|---|
| Security | What is sensitive? Callers authenticate with service tokens. Phone numbers, emails and device tokens are PII, encrypted at rest. Honour unsubscribe (GDPR, CAN-SPAM). Never log OTP values. |
| Count | How big? About 150M notifications a day, ~1.5K/s on average, and a marketing burst of 100M in ~10 minutes (~170K/s). Worked out in Step 2. |
| Availability | What must never go down? OTP and transactional stay up even if marketing is melting down. Marketing may be delayed. If a provider is down, fail over to a second one. |
| Latency | Which flows are time-critical? OTP under 5 seconds end to end (p99). Transactional under 30 seconds. A marketing campaign finishes within 30-60 minutes. |
| Exactness | Can we lose, duplicate or reorder? At-least-once delivery plus dedupe. A duplicate OTP is harmless; a lost one locks the user out. A duplicate promo is annoying; a lost one is fine. The policy is set per type. |
| Dependencies | Third parties and cost? APNs, FCM, an email provider (SES) and an SMS provider (Twilio) all have rate limits. SMS costs real money per message, so it is the cost lever. |
Step 2: Estimation
Turn the volumes into rates. The first four rows are the ones to say out loud.
| Quantity | Calculation |
|---|---|
| Volume | 100M users × 30% active × 5 per day = 150M per day |
| Average | 150M / 10^5 s = ~1.5K per second (exact ~1.7K) |
| Burst | 100M in 10 min = 100M / 600 s = ~170K per second, about 100x the average |
| Throttled burst | Spread over 1 hour: 100M / 3,600 s = ~28K per second. This is the rate the providers must accept. |
| Workers | 28K/s at ~1K sends/s per worker (assumed, async HTTP/2) = ~30 workers |
| Channels | 70% push, 25% email, 5% SMS = 105M, 37M and 7.5M per day |
| Bandwidth | 170K/s × ~1 KB push = ~170 MB/s unthrottled, ~28 MB/s throttled |
| Log | 150M per day × ~200 B = ~30 GB per day, ~2.7 TB for 90 days |
| Tokens | 100M users × ~2 devices × ~200 B = ~40 GB, small enough for a cache cluster |
| SMS cost | 7.5M per day × ~1 cent (assumed) = ~$75K per day |
Three conclusions. The average is tiny, so storage and the log are not the problem. The 100x gap between average and burst is the design driver: you cannot size for the average, so you shape the burst. And SMS cost makes channel choice a budget decision, not only a technical one.
Step 3: APIs and data model
Open with the endpoints, then the tables. Sending is asynchronous, so the send API returns 202 Accepted with an id, not a delivery result.
POST /v1/notificationssends one message. Body:user_id,type(otp, transactional or marketing),template_id,params. Needs anIdempotency-Keyheader. Returns202with anotification_id.POST /v1/campaignscreates a campaign. Body:segment,template_id,channels,send_at,max_rate. One job, not 100M requests. Returns202with acampaign_id.GET /v1/campaigns/{id}returns progress counters.POST /v1/campaigns/{id}/pauseis the kill switch: a wrong campaign must be stoppable in seconds.GET /v1/notifications/{id}returns the status: queued, sending, sent, delivered or failed.PUT /v1/users/{id}/preferencessets opt-in per channel, quiet hours and time zone.POST /v1/users/{id}/devicesregisters a device token. Written rarely, read on every send.POST /v1/provider-callbacks/{provider}receives delivery receipts, bounces and invalid-token reports from the providers.
| Table | Key and fields | Store and why |
|---|---|---|
preferences | Key (user_id, channel). Fields: opt_in, quiet hours, tz, daily_cap. | Key-value store (DynamoDB or sharded Postgres) with a Redis cache in front. Read-heavy: 170K checks per second at the burst. |
devices | Key (user_id, device_id). Fields: token, platform, last_seen, valid. | Same store. A token is flipped to valid=false after provider feedback. |
notifications | Key notification_id. Fields: user_id, type, campaign_id, channel, status, attempts. | Write-heavy log, partitioned by time with a 90-day TTL. Wide-column or time-partitioned SQL. |
campaigns | Key campaign_id. Fields: segment, template_id, status, chunks_total, chunks_done. | Small relational table. It holds the checkpoint for resuming a job. |
dedupe | Unique key notification_id, or (campaign_id, user_id). | Redis SET NX with a TTL, backed by a unique constraint in the log. |
Step 4: High-level design
Now draw the boxes. Here is the whole picture, then the same flow in words. The numbers on the diagram match the numbered list below.
- Notification Service takes the call from the API gateway, validates it and returns 202 straight away. A single message (an OTP, say) then skips fan-out and goes to step 4.
- Idempotency and log. It checks the idempotency key in Redis (
SET NX) and writes aqueuedrow to the notification DB, so a retried call never creates a second notification. - Campaign path. The Campaign Service creates one job, splits the segment into chunks of 1,000 users on a chunk queue, and fan-out workers expand each chunk into per-user messages.
- Per-user checks (opt-in, frequency cap, quiet hours, dedupe) read preferences and device tokens from a Redis cache over the database. This is where the async boundary sits.
- Priority queues. Each message goes onto an
otp,transactionalormarketingtopic, and each topic has its own worker pool. This is the hard part: a marketing backlog can never sit in front of an OTP. - Workers send through APNs/FCM, SES and Twilio, rate-limited per provider, with reserved capacity for OTP and a throttled pool for marketing.
- Callbacks and failures. Providers call back with receipts, bounces and dead tokens, and a webhook handler updates the notification DB. Failed sends retry with backoff and jitter, then land in a dead-letter queue.
Step 5: Deep dive on the hard parts
You will not cover everything below in 12 minutes. Open with the hard part you named (priority and dedupe), then give the rest one sentence each unless the interviewer pulls you in.
5a. Priority isolation
- Partitions do not give priority inside one queue. If OTPs and marketing share a topic, a 100M backlog sits in front of the OTP (head-of-line blocking). More consumers just drain the whole backlog faster.
- Use separate queues or topics per priority, each with its own consumer pool.
- Throttle marketing to the provider rate limits and spread the send over 30-60 minutes. Blasting 170K/s gets you throttled or blocked.
- Give OTP reserved capacity, such as a dedicated provider route or SMS sender, so marketing can never use up the quota.
5b. Fan-out: "send to all 100M"
- The click creates one campaign job, not 100M requests.
- A fan-out worker splits users into chunks (say 1,000 user IDs per chunk, by ID range) and puts each chunk on a queue.
- Many workers take chunks in parallel and expand each into per-user messages.
- Each chunk is checkpointed, so if a worker dies the job resumes instead of restarting or double-sending.
- For local-time sends (9am local), spread by time zone. It also flattens the burst for free.
5c. Per-user checks before sending
- Opt-in and preferences: unsubscribed, or marketing push turned off? Legally required (GDPR, CAN-SPAM).
- Channel eligibility: valid push device token, verified email, phone number present.
- Frequency cap: no more than N marketing messages per user per day.
- Quiet hours and time zone: no sale push at 3am local time.
- Dedupe: has this user already received this campaign? Key on
campaign_id + user_id. - Active users first (recently used before rarely used) is a good marketing optimization.
- These lookups live in a fast store (Redis, or a DB with a cache): 170K checks per second cannot hit a slow DB. Fetch a whole chunk at once (batched
MGET) instead of one call per user.
5d. Retries, duplicates and the DLQ
A provider timeout is ambiguous: the push might have been sent and the reply lost, or not sent at all.
- Retry transient failures (timeouts, 5xx) with exponential backoff plus jitter (1s, 2s, 4s, with randomness), capped at 3-5 attempts.
- Do not retry permanent failures (invalid device token, unsubscribed). Mark the token dead and drop it.
- After max attempts, send to a dead-letter queue (DLQ) for inspection or replay.
- Every notification has a unique
notification_id. Before sending, record it as "sending" with an atomic conditional insert (RedisSET NXor a DB unique key). If it exists, it is a retry or duplicate. After the provider confirms, mark it "sent". - Pass the id to the provider as an idempotency or collapse key where supported. APNs and FCM collapse IDs make a repeated push replace the earlier one.
The crash window. A worker crashes after the provider sent the push but before marking it "sent". On retry it sends again, so the user gets a duplicate. You cannot fully solve this, because it is unknowable whether the provider received it. So choose a policy per type:
| Type | On ambiguity | Why |
|---|---|---|
| OTP | Resend | A duplicate code is harmless; a lost one locks the user out |
| Payment alert | Resend | Losing it is worse than a duplicate |
| Marketing | Skip | Losing one promo push is better than a duplicate |
A rare duplicate is usually acceptable, since it needs a crash in a tiny window. What is unacceptable is a design that creates duplicates routinely, like retrying with no dedupe.
Check yourselfWhy did the OTP get stuck behind marketing, and what is the fix?
They shared one queue, so the 100M marketing backlog was ahead of it (head-of-line blocking). Give each priority its own queue and consumer pool, throttle marketing to provider limits, and reserve provider capacity for OTP.
The four what-ifs, per box
Once the boxes exist, ask four questions of each one: what if it is slow, down, duplicated, or 100x bigger? This is the part candidates skip.
Notification service
- Slow: return
202fast and never wait on providers. - Down: it is stateless, so run many. Callers retry with the same idempotency key.
- Duplicated: the idempotency key returns the original
notification_id. - 100x: scale out behind the load balancer. It only enqueues.
Priority queues
- Slow: backpressure. Marketing waits; the OTP pool is separate.
- Down: a replicated broker. Producers buffer and retry.
- Duplicated: consumers are idempotent through the dedupe key.
- 100x: more partitions, and a separate cluster for OTP.
Channel workers
- Slow: a circuit breaker and timeout per provider, so one slow provider cannot block the others.
- Down: another worker takes the chunk. The checkpoint prevents a restart from zero.
- Duplicated: the dedupe record is written before sending, plus the collapse key.
- 100x: add workers per provider, up to the provider's rate limit.
Providers
- Slow: back off with jitter, and shed marketing first.
- Down: fail over to a second email or SMS provider. For push, queue and retry.
- Duplicated: idempotency or collapse key where supported.
- 100x: the rate limit is the real ceiling. Spread the send and add accounts.
Preference and dedupe store
- Slow: serve from the cache. For marketing, fail closed (skip) if it is unreachable.
- Down: use replicas. For OTP, send anyway.
- Duplicated:
SET NXmakes the second write a no-op. - 100x: shard by
user_idand batch lookups per chunk.
Step 6: Where it breaks at 10x
Name the bottleneck, then the fix. Say it before the interviewer asks.
- Providers, not our servers, are the ceiling. A 1.7M/s burst is not something APNs, FCM or an SMS carrier will accept. The answer is a longer spread, more provider accounts and regions, and marketing at the lowest priority.
- The preference and dedupe lookups become the hot path at 1.7M checks per second. Shard by
user_id, cache aggressively and batch per chunk. Check the cache hit ratio before adding hardware. - The notification log grows to ~300 GB a day. Partition by time, shorten the TTL, and archive cold data to cheap storage.
- SMS cost grows linearly. Prefer push and email, and use SMS only where it is required (OTP) or pays for itself.
Monitoring, next steps and trade-offs
What I would monitor
- Delivery rate per channel and provider, with an alert on a sudden drop.
- End-to-end latency per priority, with OTP tracked separately from marketing.
- Queue depth and consumer lag per priority. DLQ depth and age.
- Provider throttle responses (429s), dead-token rate, and the duplicate-send rate (should be near zero).
- Cost per day per channel against the budget.
What I would build differently with more time
- Multi-region. Run queues and workers per region, route each user to a home region, and decide what happens to in-flight notifications and dedupe state if a region fails.
- A second provider per channel with automatic failover and health scoring.
- Digests and smart batching, so a user with 12 pending alerts gets one message.
- Rollout safety: feature flags, a canary campaign to 0.1% of users first, and the kill switch.
Trade-offs to say aloud
- At-least-once delivery with dedupe, not "exactly once". Exactly-once end to end is not possible when a provider reply can be lost.
- Separate queues per priority cost more infrastructure, but a single queue cannot protect OTPs.
- Failing closed for marketing (skip when unsure) and open for OTP (send when unsure) is a policy, not a bug.
Check yourselfThe interviewer asks what makes this problem special. What do you say in one breath?
A 100x gap between average and burst traffic, two kinds of messages with opposite needs (OTP must be fast and never lost, marketing can wait and must never be duplicated), and third-party providers that set the real rate limit. So: separate priority queues, throttled fan-out, and a per-type dedupe policy.
Summary: say it in the interview
- "I will assume 100M registered users, about 30M daily active, around 5 notifications per active user per day. Tell me if any of that is off."
- "The average is ~1.7K/s but the burst is ~170K/s, so I will not size for the peak. I will queue it, throttle marketing to the provider limits, and keep reserved capacity for OTPs."
- "At-least-once delivery with retries (backoff and jitter), an idempotency key to dedupe, a DLQ for failures, a duplicate-versus-loss policy per notification type, and separate queues so a 100M marketing burst can never delay an OTP."