StackMonkey
Home / Templates / Notification System

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.

Daily Dispatches
500M / day
Multi-channel delivery
Peak Ingress Rate
50,000 req/s
Flash marketing campaigns
P0 (OTP) SLA Latency
< 2.0 s
Two-factor auth delivery
Delivery Semantics
At-Least-Once
With client deduplication
Step 1 of 4

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.
Step 2 of 4

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 user.opted_out(channel): DROP
if current_time in user.quiet_hours and priority < P0:
  schedule_delay(queue, user.quiet_hours.end)
else: enqueue_immediate(channel_queue)
Step 3 of 4

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.

The Thread Pool Starvation Collapse

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.

Production Mitigations
  • 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.
Step 4 of 4

Six-Component Notification Infrastructure

The complete fault-tolerant architecture from event ingestion down to carrier vendor dispatch.

01 路 Ingestion API Gateway
gRPC / REST Ingestion Nodes
Authenticates service calls, validates template variables, verifies idempotency tokens, and enqueues events to RabbitMQ in under 5ms.
02 路 Deduplication & Rate Cache
Redis Cluster
Stores 24-hour idempotency tokens and per-user notification frequency counters. Drops duplicates and prevents marketing spam.
03 路 Priority Message Broker
RabbitMQ / Apache Pulsar
Partitions tasks into isolated P0 (Critical), P1 (Transactional), and P2 (Promotional) priority queues across APNs, FCM, SMS, and Email channels.
04 路 Dedicated Channel Workers
Go / Python Worker Fleet
Pulls messages from assigned priority queues. Hydrates user contact information and executes HTTP/2 and REST dispatches to vendors.
05 路 Vendor Circuit Breakers
Failover Routing Controller
Monitors carrier delivery status. Automatically shifts outbound traffic between Twilio, AWS SNS, and Sinch based on real-time error rates.
06 路 Delivery Receipt & Audit Log
ClickHouse / ScyllaDB
Stores immutable delivery receipts, webhook callbacks, open rates, and unsubscribe events for compliance and debugging analysis.
Interactive Discrete Event Simulation

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.