Design a High-Throughput Notification Platform
System DesignModel answerLast updated
Build a system that ingests notification requests with sub-50ms latency, handles 10x traffic spikes, and delivers across multiple channels without overwhelming providers.
Problem
You're building a notification platform that sends messages through multiple channels: push notifications, SMS, and email. The system must handle both routine traffic and sudden spikes during high-volume events like flash sales or promotional campaigns.
Core Requirements
What the System Must Do
- Accept requests: Receive notification requests specifying recipient, delivery channel, message content, and urgency level
- Support multiple channels: Deliver through mobile push (iOS/Android), SMS carriers, and email providers
- Prevent duplicates: Ensure the same notification isn't sent multiple times when clients retry requests
- Track delivery: Allow clients to query whether their notification was accepted and its current state
Performance and Reliability Constraints
- Fast acknowledgment: Confirm receipt within 50ms at the 99th percentile
- Handle bursts: Scale from baseline 10,000 requests/second to 100,000 requests/second within seconds
- No data loss: Once acknowledged, messages must eventually be delivered
- Priority handling: Time-sensitive messages (login codes, security alerts) cannot be delayed by bulk marketing sends
- Respect limits: Stay within third-party provider rate limits to avoid throttling or bans
Traffic Characteristics
- Baseline: 10,000 requests/sec
- Burst peak: 100,000 requests/sec
- Average message size: 2 KB
- Delivery targets: urgent messages within 5 seconds, routine messages within 2 minutes
Design Scope
Your design should address:
- API contract: How clients submit notifications and check status
- System architecture: Components and how they interact
- Queue design: How to buffer work and scale processing independently
- Traffic management: Handling overload without dropping acknowledged messages
- Reliability patterns: Deduplication, retries, and failure recovery
Hints
Hint 1
Separate accepting a request from doing the expensive work of actually sending it
Hint 2
Use separate queues for different priority levels so urgent messages aren't blocked by bulk traffic
Hint 3
Think about what happens when downstream providers are slower than your ingestion rate
Model answer
Medium Try it yourself first — then compare your approach, complexity and edge cases.
Solution Approach
This problem tests your ability to design systems where ingestion speed and processing speed are fundamentally different. The key insight is decoupling: accept requests quickly into durable storage, then process them asynchronously while respecting downstream constraints.
1. Requirements Analysis
First, validate assumptions with your interviewer:
- Does "acknowledged" mean "durably stored" or "delivered to recipient"? (Answer: durably stored)
- Are messages pre-rendered or do we need templating? (Assume mostly rendered, about 2 KB)
- How long do traffic bursts typically last? (Assume minutes to tens of minutes)
Capacity calculations:
- Peak ingestion: 100K req/s × 2 KB = 200 MB/s raw throughput
- With 3x replication: 600 MB/s across the storage layer
- 10-minute burst: 60 million messages = 120 GB of data
- If message bus partitions handle ~10 MB/s each, need 20+ partitions for throughput (provision 64-128 for consumer parallelism)
The critical observation: if downstream SMS providers only accept 5,000/sec total and 30% of your burst is SMS, you're ingesting SMS 6x faster than you can send it. The queue absorbs this mismatch.
2. API Design
POST /v1/notifications
Headers:
Idempotency-Key: <client-generated-uuid>
X-Client-ID: <service-identifier>
Body: {
recipient: "[email protected]" | "+1234567890" | "device-token",
channel: "PUSH" | "SMS" | "EMAIL",
priority: "URGENT" | "STANDARD" | "BULK",
payload: { ... } | { template_id, variables },
ttl_seconds: 300 // optional expiration
}
Returns: 202 Accepted
{
notification_id: "uuid",
status: "ACCEPTED"
}
Errors:
429 Too Many Requests (with Retry-After header)
409 Conflict (idempotency key reused with different body)
POST /v1/notifications/batch // up to 500 items, returns per-item status
GET /v1/notifications/{id}
Returns: {
status: "ACCEPTED" | "DISPATCHED" | "DELIVERED" | "FAILED" | "EXPIRED",
retry_count: 2,
last_error: "..."
}
Return 202 Accepted, not 200 OK—this signals the request is queued but not yet completed. The ttl_seconds field allows discarding stale marketing messages rather than delivering them hours late.
3. High-Level Architecture
┌─────────┐
│ Clients │
└────┬────┘
│
┌────▼────────────────────┐
│ API Layer (Stateless) │
│ - Auth & validation │
│ - Quota enforcement │
│ - Idempotency check │
│ - Produce to queue │
└────┬────────────────────┘
│ writes with durability guarantees
┌────▼──────────────────────────────────┐
│ Message Queue (Kafka/Kinesis) │
│ Topics: urgent-push, urgent-sms, │
│ standard-push, bulk-email... │
└────┬──────────────────────────────────┘
│ consume by priority/channel
┌────▼──────────────────────────────────┐
│ Worker Pools (per priority/channel) │
│ - Rate limiting (per provider) │
│ - Circuit breaking │
│ - Provider API calls │
└────┬──────────────────────────────────┘
│
┌────▼─────────────────┐
│ Provider APIs │
│ (APNs, FCM, Twilio, │
│ SendGrid, etc.) │
└──────────────────────┘
Side paths:
- Idempotency store (Redis/DynamoDB, 24h TTL)
- Status tracking store (DynamoDB, keyed by notification_id)
- Retry queues (with backoff delays)
- Dead letter queue (for permanent failures)
Latency budget for ingestion:
- Authentication and validation: ~1ms
- Idempotency check (cached): 1-3ms
- Queue write with acknowledgment: 5-15ms (with proper replication)
- Total: comfortably under 50ms p99
Keep producer connections warm and use minimal batching windows (2-5ms) so batching doesn't inflate tail latency.
4. Queue Topology and Scaling
Topic organization: Create separate topics for each combination of priority and channel (e.g., urgent-sms, bulk-email). This ensures:
- Urgent security codes never wait behind marketing emails
- An outage in push notification delivery doesn't block SMS
- Independent scaling per workload type
Partitioning strategy: Partition by recipient_id for:
- Per-user ordering (e.g., "order shipped" before "order delivered")
- Consistent frequency capping per user
- Load distribution (hot users are rare; for broadcasts, partition by message_id instead)
Worker pool design:
- Urgent pools: Pre-provisioned for peak capacity, never scaled to zero, sized for maximum expected load
- Standard/bulk pools: Auto-scale based on consumer lag, not CPU utilization
- Scale out when lag grows faster than drain rate
- Cap scaling at partition count (more workers than partitions is wasteful)
- Cap at provider quota limits (more workers than available tokens is pointless)
Burst preparation: Auto-scaling takes 30-60 seconds to provision new capacity. For predictable events, pre-warm infrastructure. Otherwise, maintain 2-3x baseline capacity so the initial spike is absorbed while scaling activates.
5. Overload Control and Backpressure
Ingress quotas (per client service):
- Token bucket per client: sustained rate + burst allowance
- Separate quota for URGENT tier that cannot be consumed by bulk traffic
- Enforce locally on API nodes using periodically synchronized allocations from central store (avoids per-request coordination)
- Return 429 with
Retry-Afterheader when exceeded
Egress rate limiting (per provider):
- Distributed token buckets matching contractual limits (e.g., 5,000 SMS/sec per provider)
- Workers lease token batches (e.g., 100 tokens at a time) to avoid per-message coordination
- Weighted fair sharing: urgent gets 70% of capacity, can borrow unused bulk capacity (but not vice versa)
Backpressure mechanism:
- When tokens depleted, workers pause consumption rather than buffering in memory
- Queue lag becomes the buffer—this is why durable queues are essential
- Monitor lag metrics to trigger auto-scaling and client throttling
Load shedding (ordered by preference):
- Drop expired bulk messages (past their TTL) at dequeue time
- Throttle BULK tier at ingress when projected drain time exceeds SLA (e.g., 2+ minutes)
- Never shed URGENT tier
- Crucially: shed before acknowledgment, never after—once acked, delivery is guaranteed
6. Idempotency and Failure Handling
Deduplication at ingress:
- Client generates idempotency key (UUID)
- API stores
SET key="{client}:{idem_key}" value="PENDING" NX EX 300(5 min) - Write to queue with replication
- Update key to
"ACCEPTED:{notification_id}:{body_hash}" EX 86400(24 hours)
On retry:
- If key shows ACCEPTED: return cached response immediately
- If PENDING: return 409 or ask to retry shortly
- If write fails: delete PENDING key so retry succeeds
Short PENDING TTL prevents crashed nodes from permanently blocking keys.
Consumer-side deduplication:
- Message queues provide at-least-once delivery, so workers check
dispatched:{notification_id}before sending - Commit consumer offset only after recording outcome in status store
Retry strategy:
- Transient errors (5xx, timeouts, provider throttling): send to delay queues with exponential backoff (30s, 5min, 30min)
- Retries processed separately so failing messages don't block partition consumption
- Permanent errors (invalid recipient, unsubscribed): fail immediately, update status, possibly trigger cleanup
- After max retries or expiration: move to dead letter queue for manual review
Circuit breakers:
- Per-provider circuit breaker prevents thundering herd when a provider is degraded
- Opens after consecutive failure threshold
- Half-open probes allow recovery detection
- While open, immediately fail with retriable error to delay queue
7. Common Mistakes and Trade-offs
Mistakes to avoid:
- Doing provider calls synchronously in the API path (destroys latency)
- Using a single queue for all priorities (bulk traffic delays urgent messages)
- Infinite retries without exponential backoff (amplifies load during outages)
- Not pre-warming connections (cold start latency kills p99)
- Forgetting that exactly-once delivery to third-party providers is impossible (design for idempotent retry)
Key trade-offs:
- Queue choice: Kafka gives ordering, replay, and high throughput but requires operational complexity. SQS is simpler but lacks ordering and replay capabilities. For this use case, the burst absorption and pause/resume needs favor Kafka.
- Deduplication window: 24 hours catches most retries but uses storage. Tune based on actual client behavior.
- Priority tiers: More tiers = finer control but more operational overhead. Three (urgent/standard/bulk) is usually sufficient.
- Synchronous vs eventual consistency: Status API returns eventually consistent data from the status store (DynamoDB) for performance. For critical use cases, could add synchronous read-after-write for just-created notifications.
8. Monitoring and Observability
Critical metrics:
- Ingestion latency p50/p99/p999
- Queue lag per topic (messages and time behind)
- Provider success rate and latency per channel
- Token bucket utilization per provider
- Retry queue depth
- Messages in dead letter queue
- End-to-end delivery time by priority tier
Alert on:
- Ingestion p99 > 50ms
- Queue lag growth rate exceeding drain rate
- Provider error rate > 5%
- Circuit breaker opens
- Urgent tier messages older than 10 seconds in queue
This design achieves the sub-50ms acknowledgment goal by doing minimal work in the ingestion path, absorbs bursts through durable queuing with independent scaling, protects downstream providers with rate limiting and circuit breaking, and ensures reliability through idempotency and structured retry logic.