Designing a Scalable Multi-Channel Notification Engine
Delivering 500 million daily notifications across SMS, Push (APNs / FCM), and Email requires priority queue tiering, external vendor circuit breakers, user preference filtering, and distributed deduplication guarantees.
Priority Breakdown & Vendor Rate Limits
Third-party communication providers (Twilio, SendGrid, Apple APNs, Google FCM) enforce strict external rate limits and variable latencies. The notification engine must buffer, throttle, and isolate traffic channels.
Volume Breakdown by Channel
- 1. Mobile Push (60%): 300M alerts/day. Dispatched over persistent HTTP/2 sockets to Apple APNs and Google FCM. Average latency: 80ms.
- 2. Email (30%): 150M emails/day. Delivered via SMTP / API pools (SendGrid, AWS SES). Average latency: 350ms.
- 3. SMS (10%): 50M messages/day. High-cost, strictly regulated carrier path (Twilio, Sinch). Average latency: 250ms. Hard vendor limit: 100 SMS/sec per shortcode.
Queue Sizing & Priority Tiering
- 1. P0 Critical (OTP / Fraud Alerts): SLA < 2 seconds. Never shares a queue with bulk campaigns. Dedicated worker fleet guarantees zero head-of-line blocking.
- 2. P1 Transactional (Order receipts, password resets): SLA < 30 seconds. Buffered during traffic spikes, auto-scales worker concurrency.
- 3. P2 Promotional (Marketing blasts, weekly digests): SLA < 4 hours. Throttled aggressively through rate limiters to avoid saturating email reputation and vendor limits.
Distributed Deduplication & Preference Filtering
Nothing destroys user trust faster than sending the same notification 5 times or blasting users who opted out. Discover the multi-stage filter pipeline.
Idempotency Key Verification
Every inbound notification request contains a client-provided idempotency key (or computed hash of `user_id + event_type + timestamp_bucket`).
The ingestion worker executes an atomic SET {idempotency_key} 1 NX EX 86400 in Redis. If the key already exists, the event is immediately discarded with 200 OK (Duplicate Ignored), preventing duplicated SMS charges.
User Preference & Quiet Hours Filter
Before enqueuing to channel workers, the engine queries the user preference cache:
if current_time in user.quiet_hours and priority < P0:
schedule_delay(queue, user.quiet_hours.end)
else: enqueue_immediate(channel_queue)
Third-Party Vendor Outage & Poison Queue Saturation
When an external vendor (e.g. Twilio SMS gateway) suffers downtime, worker threads block waiting for HTTP timeouts. See how an external failure collapses internal message queues.
Suppose the SMS worker fleet has 100 worker threads, normally processing requests in 200ms (sustainable throughput: 500 SMS/sec).
The upstream vendor gateway becomes unresponsive, holding TCP connections until the 10-second socket timeout expires.
Within 2 seconds, all 100 threads are blocked in `READ_TIMEOUT`. Worker throughput drops from 500/s to 10/s. Inbound messages accumulate in RabbitMQ at 5,000/s. Memory usage crosses threshold $K$, triggering broker node swapping and halting all channels.
- Automated Vendor Circuit Breaker: Trip circuit if failure rate > 5% over 10 seconds. Automatically route SMS requests to secondary carrier (e.g. AWS SNS fallback).
- Dead-Letter Queue (DLQ) with Exponential Backoff: Failed deliveries move to a DLQ after 3 failed retries. DLQ messages are re-tested with exponential backoff and jitter.
- Aggressive Socket Timeouts: Set connection timeout = 1.0s, read timeout = 2.5s. Fast failures prevent worker thread starvation.
Six-Component Notification Infrastructure
The complete fault-tolerant architecture from event ingestion down to carrier vendor dispatch.
Simulate the Notification System Live
Model priority queue isolation between SMS OTPs and email marketing blasts, simulate vendor outages, and test circuit breaker failover live.