Mock design: notification system

Lesson 2.1 · 20 min read · by Vinay C

We'll cover the following

Visual summary

Infographic summarizing Mock design: notification system: Prompt: "Design a notification system that sends push, email and SMS to 100M users." This lesson follows the order…

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.

MinutesStep and what you produce
0-7Requirements. Two columns on the board, an out-of-scope list, assumed numbers.
7-12Estimation. Average and peak QPS, storage, provider cost.
12-18APIs and data model. Endpoints, tables, one store per table.
18-28High-level design. The boxes, one line each.
28-40Deep dive. Priority queues, fan-out, dedupe, retries.
40-45Bottlenecks 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)

LetterAsked and agreed
ActorsWho uses it? Internal services (orders, payments, auth) trigger single messages. Marketers trigger campaigns. End users receive them and manage preferences.
Core flowsWhat 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.
TriggersHow 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.
OutputsWhat 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.
RulesWhich 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).
ScopeWhat 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)

LetterAsked and agreed
SecurityWhat 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.
CountHow 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.
AvailabilityWhat 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.
LatencyWhich flows are time-critical? OTP under 5 seconds end to end (p99). Transactional under 30 seconds. A marketing campaign finishes within 30-60 minutes.
ExactnessCan 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.
DependenciesThird 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.

QuantityCalculation
Volume100M users × 30% active × 5 per day = 150M per day
Average150M / 10^5 s = ~1.5K per second (exact ~1.7K)
Burst100M in 10 min = 100M / 600 s = ~170K per second, about 100x the average
Throttled burstSpread over 1 hour: 100M / 3,600 s = ~28K per second. This is the rate the providers must accept.
Workers28K/s at ~1K sends/s per worker (assumed, async HTTP/2) = ~30 workers
Channels70% push, 25% email, 5% SMS = 105M, 37M and 7.5M per day
Bandwidth170K/s × ~1 KB push = ~170 MB/s unthrottled, ~28 MB/s throttled
Log150M per day × ~200 B = ~30 GB per day, ~2.7 TB for 90 days
Tokens100M users × ~2 devices × ~200 B = ~40 GB, small enough for a cache cluster
SMS cost7.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/notifications sends one message. Body: user_id, type (otp, transactional or marketing), template_id, params. Needs an Idempotency-Key header. Returns 202 with a notification_id.
  • POST /v1/campaigns creates a campaign. Body: segment, template_id, channels, send_at, max_rate. One job, not 100M requests. Returns 202 with a campaign_id.
  • GET /v1/campaigns/{id} returns progress counters. POST /v1/campaigns/{id}/pause is 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}/preferences sets opt-in per channel, quiet hours and time zone. POST /v1/users/{id}/devices registers 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.
TableKey and fieldsStore and why
preferencesKey (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.
devicesKey (user_id, device_id). Fields: token, platform, last_seen, valid.Same store. A token is flipped to valid=false after provider feedback.
notificationsKey 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.
campaignsKey campaign_id. Fields: segment, template_id, status, chunks_total, chunks_done.Small relational table. It holds the checkpoint for resuming a job.
dedupeUnique 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.

Architecture diagram with seven numbered steps. Backend services, the marketer UI and a scheduler call an API gateway. Inside the synchronous path, a Notification Service validates the request, checks Redis for the idempotency key, writes a row to the notification DB and returns 202 (steps 1 and 2). A Campaign Service puts 1,000-user chunks on a chunk queue for fan-out workers (step 3). Below the async boundary, per-user checks use a preferences and device store (step 4). Messages then go to three Kafka topics, otp, transactional and marketing, each with its own worker pool (step 5; the hard part). Workers call APNs/FCM, SES and Twilio (step 6). Provider callbacks go to a webhook handler that updates the notification DB, and failures go to retry and then a dead-letter queue (step 7).
High-level design. Sync path on top, async delivery below, one queue and one pool per priority. Open full size
  1. 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.
  2. Idempotency and log. It checks the idempotency key in Redis (SET NX) and writes a queued row to the notification DB, so a retried call never creates a second notification.
  3. 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.
  4. 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.
  5. Priority queues. Each message goes onto an otp, transactional or marketing topic, and each topic has its own worker pool. This is the hard part: a marketing backlog can never sit in front of an OTP.
  6. Workers send through APNs/FCM, SES and Twilio, rate-limited per provider, with reserved capacity for OTP and a throttled pool for marketing.
  7. 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 (Redis SET NX or 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:

TypeOn ambiguityWhy
OTPResendA duplicate code is harmless; a lost one locks the user out
Payment alertResendLosing it is worse than a duplicate
MarketingSkipLosing 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 202 fast 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 NX makes the second write a no-op.
  • 100x: shard by user_id and 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."