Design a Multi-Channel Notification Delivery Platform at Scale
System DesignModel answerLast updated
Design a globally distributed system that delivers billions of push, email, and SMS notifications daily with low latency, at-least-once guarantees, and no duplicates on retry.
Background
Your company runs a platform used by millions of services — e-commerce checkouts, ride-hailing apps, banking apps — all of which need to reach their end users through push notifications, email, and SMS. You are asked to design the backend infrastructure that powers this.
What You Need to Design
A multi-channel notification platform that can handle peak ingest of 100,000 requests per second, deliver messages to users anywhere in the world with sub-500ms p95 latency for push, and guarantee at-least-once delivery without ever sending a duplicate to the same user from the same originating request.
Functional Requirements
- Accept notification requests from internal services via a single unified API.
- Deliver across three channels: mobile push (APNs/FCM), email, and SMS.
- Continue delivering messages even when a third-party provider (e.g., an SMS gateway or email relay) is temporarily unavailable.
- Support channel fallback: if push fails, try SMS instead.
Non-Functional Requirements
| Property | Target |
|---|---|
| Peak ingest | 100,000 RPS |
| Push latency | < 500ms p95 end-to-end |
| Delivery guarantee | At-least-once |
| Duplicate protection | Idempotent across retries and region failovers |
| Availability | Multi-region, no single region as SPOF |
What Your Answer Should Cover
- A high-level architecture with the key components and how they interact.
- The API contract for submitting a notification request.
- How messages are persisted, queued, and processed in the background.
- How idempotency is maintained end-to-end, including the honest limitation.
- How the system is deployed across regions and how global traffic is routed.
- How failures are handled: retries, circuit breakers, dead-letter queues, and observability.
Hints
Hint 1
Start by separating the ingest path from the delivery path. The API should return immediately (202 Accepted) and hand off work to a durable queue — this is what lets you absorb traffic spikes without dropping messages. Ask yourself: what is the source of truth once the caller gets a 202?
Hint 2
Idempotency has two distinct layers: (1) making sure the same API call from a caller doesn't create two separate jobs, and (2) making sure the same job doesn't call the provider twice even if a worker crashes mid-flight. Think about what data structure and what atomic operation you need for each layer, and be honest about where the remaining gap is.
Hint 3
Think about why push, email, and SMS need separate worker pools rather than one shared pool. A backed-up email queue should never add latency to a push notification. Then consider what the multi-region story looks like for the deduplification store — a per-region store is fast but risks duplicates on failover, while a globally consistent store adds latency. Name the trade-off explicitly.
Model answer
Medium Try it yourself first — then compare your approach, complexity and edge cases.
How to Approach This Problem
A strong answer has four pillars: decoupling ingest from delivery via a durable log, a concrete idempotency strategy with an honest acknowledgment of its limits, a multi-region plan with real trade-offs, and operational maturity around failures and observability.
1. Clarify and Estimate Before Drawing Anything
Questions worth asking:
- Are notifications transactional (OTP, payment alert) or marketing? This drives priority and TTL design.
- Is fan-out one user per request or a segment of millions? Fan-out changes the architecture significantly.
- Is per-user, per-channel ordering required? Usually best-effort is fine.
Back-of-envelope numbers from the requirements:
- 5B notifications/day → ~58K/s average, 100K/s peak
- At ~1 KB average payload: ~100 MB/s ingest bandwidth
- Log storage: ~5 TB/day, ~150 TB for 30-day retention (tiered object store)
- Idempotency keys at 100K/s with 24h TTL: ~8.6B live keys, ~860 GB at 100 bytes each — this rules out a single Redis node; you need a partitioned KV store
- Channel mix (illustrative): 70% push, 20% email, 10% SMS
Two facts constrain the design: push has a hard 500ms p95 budget; email and SMS are provider-dominated and measured in seconds. Slow channels must never block the fast path.
2. API Design
POST /v1/notifications
Headers: Idempotency-Key: <client-generated UUID>, Authorization: Bearer <token>
Body:
{
"recipient": { "user_id": "u_abc123" },
"channels": ["push", "email"], // or "auto" to use stored preferences
"priority": "critical|high|normal|bulk",
"template_id": "order_confirmed",
"params": { "order_id": "O-9999" },
"ttl_seconds": 3600, // drop if not delivered in window
"fallback_channels": ["sms"] // tried in order if primary channels fail
}
→ 202 Accepted
{ "notification_id": "n_xyz789", "status": "QUEUED" }
Key decisions:
- 202, not 200 — delivery is async. A 200 would imply the message was sent.
- A repeated
Idempotency-Keyfrom the same caller returns the originalnotification_idwithout creating a second job. - Callers can poll
GET /v1/notifications/{id}for per-channel status (QUEUED / SENT / DELIVERED / FAILED) or register a webhook for push-based receipts.
3. High-Level Architecture
Callers ──► GeoDNS / Anycast LB ──► Regional API Gateway (auth, rate limiting)
│
Notification Service
(validate, idempotency check, write to log)
│
Durable log (Kafka), topics by priority:
[critical] [high] [normal] [bulk]
│
Router / Fan-out workers
(expand segments, apply user preferences,
resolve device tokens, render templates)
│
Channel-specific topics: [push] [email] [sms]
│ │ │
Push workers Email workers SMS workers
(APNs, FCM) (SES, SendGrid) (Twilio, Vonage)
│ │ │
Provider-level rate limiters + circuit breakers
│
Delivery State Store (Spanner / Bigtable / Cassandra)
← provider delivery receipts via webhook
Retry topics (tiered backoff) → Dead-letter queue (DLQ)
The two-stage pipeline — router first, then per-channel workers — is the key structural decision. It means email backpressure never touches the push pipeline.
4. Persistence, Queuing, and Idempotency
Ingest (must be fast — target < 30ms):
- Atomically insert
(caller_id, idempotency_key)into the partitioned KV store with a 24–72h TTL. If the key already exists, return the storednotification_idimmediately. - Append the job to Kafka with
acks=all(durable). Once this succeeds, at-least-once delivery is guaranteed because workers only commit offsets after processing. - Return 202.
Delivery-level idempotency is the subtler part. Each unit of work gets a deterministic ID:
delivery_id = hash(notification_id + user_id + channel + device_token)
Workers run a state machine in the delivery store using a compare-and-set (CAS):
PENDING ──(CAS + 30s lease)──► SENDING ──► SENT ──► DELIVERED
└─ failure ──► RETRY_SCHEDULED ──► FAILED / DLQ
A worker must win the CAS from PENDING → SENDING before calling the provider. If Kafka redelivers the same message (worker crash, rebalance), the worker sees SENT and skips the provider call.
The honest gap: if a worker crashes after the provider accepts the message but before writing SENT, a duplicate will be sent. True exactly-once delivery to an external API is impossible. You close this window by:
- Passing
delivery_idas the provider's idempotency key wherever supported (FCM/APNs collapse IDs, emailMessage-IDheader, Twilio idempotency keys). - Keeping the lease short (30s) to minimize the window.
Retries: use tiered retry topics (1s → 10s → 1m → 10m) rather than sleeping in workers. Always check the notification TTL before retrying — a stale OTP should be dropped, not delivered late.
5. Multi-Region Deployment
- Global routing: GeoDNS or Anycast sends callers to the nearest healthy region. Health checks fail a region out within seconds.
- Regional independence: each region runs the full stack with its own Kafka cluster. A region outage reduces capacity but doesn't take down the system.
- Idempotency store scope:
- Option A — home region by hash: simple, no cross-region reads, but adds cross-region latency for callers routed to a non-home region.
- Option B — globally consistent store (Spanner): adds ~10–50ms commit latency at ingest, but eliminates duplicate windows during failover.
- The trade-off is latency versus a brief duplicate risk. For transactional notifications (OTP, payment), Option B is worth the cost.
- User data (preferences, device tokens): replicated asynchronously to all regions. Seconds of staleness is acceptable.
6. Failure Handling, Rate Limiting, and Observability
Rate limiting:
- Inbound: per-caller token bucket at the API Gateway, enforced in a shared Redis cluster.
- Outbound: per-provider rate limiter in each channel worker pool. SMS providers often cap at a few hundred messages per second per tenant — workers must respect this or face bans.
Circuit breakers: wrap every provider call. On consecutive failures, open the circuit and either retry via a backup provider or park messages in the retry topic. Never fan retries directly into a provider that is already responding slowly.
Priority queues: critical (OTP, payment alerts) and high topics get dedicated consumer groups with more workers. bulk (marketing) topics are processed with lower concurrency and can be paused entirely under load without affecting the other tiers.
Observability — the key metrics to instrument:
- Ingest rate and p99 latency per caller
- Queue depth per topic and per channel
- End-to-end delivery latency per channel (measure at receipt webhook)
- Provider error rates (4xx vs 5xx separately — 4xx usually means bad token/address, not a provider outage)
- DLQ depth and age of oldest message
Common design mistakes to avoid:
- Calling providers synchronously in the ingest path — this couples your latency to their latency.
- Using a single Kafka topic for all channels — slow channels starve fast ones.
- Assuming idempotency keys in a single Redis node will scale — partition them.
- Forgetting TTL on retry: a retried OTP delivered 30 minutes late is a security issue, not a success.
- Not distinguishing provider 4xx (bad destination) from 5xx (transient failure) — only 5xx should trigger retries.