Design a Multi-Channel Notification Delivery Service
System DesignModel answerLast updated
Design a scalable backend service that reliably delivers notifications across email, SMS, and push channels with rate limiting and user preferences.
Scenario
You are a backend engineer at a mid-sized e-commerce platform. The product team wants to consolidate all outgoing notifications — order confirmations, shipping updates, promotional campaigns, and security alerts — into a single Notification Delivery Service owned by one team.
Currently, five different microservices each call third-party providers (email, SMS, push) directly, leading to duplicate sends, no user preference enforcement, and no visibility into delivery failures.
What You Are Asked to Design
Design the Notification Delivery Service that acts as the single entry point for all outgoing notifications.
Address the following in your design:
Functional Requirements
- Accepts notification requests from internal services (producers)
- Supports three channels: email, SMS, and in-app push
- Respects per-user channel preferences and opt-outs
- Deduplicates notifications within a configurable time window
- Tracks delivery status (sent, delivered, failed, bounced)
Non-Functional Requirements
- Scale: ~5 million registered users; peak load of 20,000 notification requests/minute during flash sales
- Latency: Security/transactional alerts must be delivered within 5 seconds of the triggering event
- Reliability: At-least-once delivery; failed sends must be retried with backoff
- Rate limiting: No user receives more than 3 promotional notifications per day per channel
Expected Coverage
- API design — what does a producer call, and what does the contract look like?
- Data model — key tables/documents and their purpose
- High-level architecture — major components and data flow
- Deep dives — deduplication, priority handling, retry logic, rate limiting
- Trade-offs — at least two meaningful decisions with pros/cons
You do not need to design the third-party provider integrations in detail. Focus on the core service.
Hints
Hint 1
Think about how you separate the act of receiving a notification request from actually dispatching it — what does that boundary buy you in terms of reliability and scalability?
Hint 2
User preferences and rate limits are read on every notification; how do you make those lookups fast without hitting a relational database on every request?
Hint 3
Transactional (security) and promotional notifications have very different latency and volume profiles — should they share the same processing path?
Model answer
Medium Try it yourself first — then compare your approach, complexity and edge cases.
1. API Design
Producers call a single internal REST (or gRPC) endpoint:
POST /v1/notifications
Request body:
{
"idempotency_key": "order-svc:order_789:shipped",
"user_id": "u_4421",
"type": "TRANSACTIONAL", // TRANSACTIONAL | PROMOTIONAL | SECURITY
"template_id": "order_shipped_v2",
"channels": ["EMAIL", "PUSH"], // preferred channels; service may override
"payload": { "order_id": "789", "carrier": "FedEx" },
"priority": "HIGH", // HIGH | NORMAL | LOW
"dedup_window_seconds": 300
}
Response:
{ "notification_id": "n_99f2a", "status": "ACCEPTED" }
The API is fire-and-forget from the producer's perspective — acceptance does not guarantee delivery, only ingestion. Producers can poll or subscribe to a delivery-status webhook.
2. Data Model
notifications table (PostgreSQL or DynamoDB)
| Column | Type | Notes |
|---|---|---|
| notification_id | UUID PK | |
| idempotency_key | VARCHAR UNIQUE | for dedup |
| user_id | UUID | FK to users |
| type | ENUM | TRANSACTIONAL / PROMOTIONAL / SECURITY |
| template_id | VARCHAR | |
| payload | JSONB | |
| priority | ENUM | |
| created_at | TIMESTAMP |
delivery_attempts table
| Column | Type | Notes |
|---|---|---|
| attempt_id | UUID PK | |
| notification_id | UUID FK | |
| channel | ENUM | EMAIL / SMS / PUSH |
| status | ENUM | PENDING / SENT / DELIVERED / FAILED / BOUNCED |
| provider_message_id | VARCHAR | third-party ref |
| attempted_at | TIMESTAMP | |
| next_retry_at | TIMESTAMP |
user_preferences table (cached in Redis)
| Column | Type |
|---|---|
| user_id | UUID PK |
| opted_out_channels | ARRAY |
| quiet_hours_start / end | TIME |
| promotional_daily_limit | INT |
rate_limit_counters — Redis sorted sets or counters, keyed rl:{user_id}:{channel}:{date}, TTL 24 h.
3. High-Level Architecture
Producers
|
v
[Ingestion API] ──> idempotency check (Redis) ──> write to notifications table
|
v
[Message Router]
|── HIGH priority ──> High-Priority Queue (Kafka topic: notif-high)
└── NORMAL/LOW ──> Normal Queue (Kafka topic: notif-normal)
|
v
[Dispatcher Workers] (one pool per channel: email, SMS, push)
|── read user preferences (Redis cache, TTL 60 s)
|── check rate limits (Redis)
|── render template
|── call third-party provider
|── write delivery_attempt record
└── on failure → Dead Letter Queue → Retry Scheduler
Key components:
- Ingestion API — stateless; horizontal scaling behind a load balancer.
- Kafka topics — two priority tiers; high-priority topic has fewer partitions but dedicated consumer groups for lower latency.
- Dispatcher Workers — stateless consumers; one worker type per channel to allow independent scaling (email volume >> SMS volume).
- Redis — holds idempotency keys (TTL = dedup window), user preference cache, and rate-limit counters.
- Retry Scheduler — polls
delivery_attemptsfor records wherenext_retry_at <= now()and re-enqueues them.
4. Deep Dives
Deduplication
On ingestion, compute a Redis key: dedup:{idempotency_key}, SET NX with TTL equal to dedup_window_seconds. If the key already exists, return 409 Duplicate without writing to the DB. This is O(1) and keeps the DB write path clean.
Priority Handling
SECURITY and order-critical TRANSACTIONAL events are marked HIGH. The high-priority Kafka topic is consumed by a dedicated worker pool with no batching (poll interval ~10 ms). Normal workers can batch up to 50 messages to improve throughput. This keeps p95 latency for security alerts under 2 s end-to-end.
Retry Logic
On a provider failure, the worker writes status=FAILED and sets next_retry_at = now() + backoff(attempt). Backoff: 30 s, 2 min, 10 min, 1 h — max 4 retries. After the 4th failure, status becomes DEAD and an alert fires to the on-call team. Retries go back through Kafka (not a separate path) so the same worker pool handles them.
Rate Limiting
Before dispatching a PROMOTIONAL notification, workers do:
INCR rl:{user_id}:{channel}:{YYYY-MM-DD}
EXPIRE rl:{...} 86400
If the counter exceeds the limit (default 3), the notification is dropped and logged. TRANSACTIONAL and SECURITY types bypass this check entirely.
5. Trade-offs
Single queue vs. priority queues Using one Kafka topic is simpler to operate but a promotional blast (millions of messages) can delay a security alert by minutes. Two topics add operational overhead (monitoring two consumer lag metrics, two deployments) but give hard latency isolation. Given the 5-second SLA for security alerts, the two-topic design is worth the complexity.
Push vs. pull for delivery status
Producers could poll /v1/notifications/{id}/status. This is simple but creates noisy traffic. Alternatively, the service posts a webhook to a registered callback URL on status change. Webhooks are lower latency and reduce polling load, but require producers to expose an endpoint and handle retries on the webhook itself. For an internal platform, webhooks are preferable; for external API consumers, offer both.
Redis cache TTL for user preferences A short TTL (10 s) means preference changes propagate quickly but increases Redis read volume. A 60 s TTL reduces load at the cost of a user's opt-out taking up to 60 s to take effect. For opt-outs (privacy-sensitive), consider an invalidation event via a Kafka topic that workers subscribe to, combining fast propagation with low read volume.
Common Mistakes to Avoid
- Synchronous provider calls in the API path — this couples your API latency to third-party SLAs and causes cascading failures.
- No idempotency key — without it, any producer retry doubles the send.
- Rate-limiting all notification types — blocking a security alert because a user already received 3 promos is a serious product and safety bug.
- Storing rate-limit state in the database — at 20,000 req/min, a SQL
UPDATEper notification for rate limiting will be a bottleneck; use Redis atomics.