BLUEPRINT #04Social & Real-Time
Design a Scalable Distributed Notification System
Referenced Architecture Primitives (7)
Click any primitive to study its algorithmic deep dive10-Stage Structure:1. Requirementsβ2. Sizingβ3. Topologyβ4. Data Modelβ5. AWS Topologyβ6. Deep-Diveβ7. Failuresβ8. SRE Playbooks
1. Problem Statement & Scope Clarification
System Mission
Design a globally distributed, highly available, multi-channel notification platform (similar to Twilio, OneSignal, and Amazon SNS/SES) capable of delivering billions of notifications daily across Mobile Push (Apple APNs, Google FCM), SMS, Transactional Email, and Webhooks, with strict priority isolation, user preference compliance (quiet hours, category opt-outs), intelligent deduplication, and rate-limiting.
Functional Requirements
- Multi-Channel Dispatch Engine: Unified API supporting Mobile Push (iOS APNs HTTP/2, Android FCM v1), SMS (Amazon SNS / Twilio), Email (Amazon SES), and In-App WebSockets.
- Strict Priority Queuing: Critical transactional messages (OTP, 2FA, fraud alerts) must bypass marketing batches and achieve sub-second delivery.
- Template Rendering & Localization: Dynamically render multi-lingual templates with personalized user variables fetched from profile stores.
- Intelligent Deduplication: Suppress duplicate notifications for the same event trigger within a configurable sliding TTL window (e.g., preventing duplicate billing alert pushes).
- User Preference & Regulatory Compliance: Enforce per-user channel preferences, quiet hour dampening across local user timezones, and statutory opt-out compliance (TCPA, GDPR, CAN-SPAM).
- Device Token Lifecycle Management: Automatically handle device token invalidations (e.g., APNs
410 Gone/ FCMUNREGISTERED) without crashing worker pipelines.
Non-Functional Requirements (SLAs & SLOs)
- High Availability: uptime SLA for critical OTP/transactional notification paths.
- Latency:
- High-Priority (OTP / 2FA / Security Alerts): Delivery P99 .
- Low-Priority (Marketing / Daily Digests): Delivery within 15 minutes of batch trigger.
- Scale: Ingest peak of ; deliver over .
- Durability: Zero acknowledged message loss ().
2. Capacity & Scale Estimation (Back-of-the-Envelope Math)
Traffic & Ingest Profile
- Total Daily Notification Volume: (2 Billion/day).
- Channel Distribution:
- Mobile Push (APNs / FCM): ().
- Transactional & Marketing Email (SES): ().
- SMS & WhatsApp (SNS / Twilio): ().
- Average Ingest QPS:
- Peak Ingest QPS ( multiplier during global flash sales):
Bandwidth & Worker Sizing
- Average Ingestion Payload Size: (Metadata + template variables).
- Peak Ingest Network Bandwidth:
- Push Worker Fleet Sizing: An HTTP/2 persistent connection to APNs handles .
3. High-Level Architecture & AWS Component Mapping
Interactive Architecture DiagramSynthesizing vector architecture diagram...
4. API Interface Design & Wire Protocol
Unified Notification Ingest Protocol (notification.proto)
protobufsyntax = "proto3"; package hispeeddesign.notification.v1; service NotificationService { rpc SendNotification (SendNotificationRequest) returns (SendNotificationResponse); rpc SendBatchNotification (SendBatchNotificationRequest) returns (SendBatchNotificationResponse); } enum PriorityLevel { PRIORITY_UNSPECIFIED = 0; PRIORITY_CRITICAL = 1; // Bypasses quiet hours, delivers via FIFO queue (OTP/MFA) PRIORITY_HIGH = 2; // Transactional receipts, billing notices PRIORITY_LOW = 3; // Marketing promotions, weekly newsletters } enum ChannelType { CHANNEL_PUSH = 0; CHANNEL_SMS = 1; CHANNEL_EMAIL = 2; CHANNEL_IN_APP = 3; } message SendNotificationRequest { string user_id = 1; string idempotency_key = 2; // Client-supplied deduplication key PriorityLevel priority = 3; repeated ChannelType preferred_channels = 4; string template_id = 5; map<string, string> template_variables = 6; int32 deduplication_window_seconds = 7; // Default: 300s } message SendNotificationResponse { string notification_id = 1; enum Status { QUEUED = 0; DROPPED_DUPLICATE = 1; DROPPED_OPT_OUT = 2; DROPPED_QUIET_HOURS = 3; } Status status = 2; int64 timestamp_ms = 3; }
5. Data Models & DynamoDB Preference & Token Schema
DynamoDB Table: NotificationUserDataTable
PK (Partition Key) | SK (Sort Key) | Attributes & Types | Description |
|---|---|---|---|
USER#<user_id> | PREFERENCES | opt_in_marketing (BOOL), quiet_hours_start (STR), quiet_hours_end (STR), timezone (STR) | User channel preferences and quiet hours |
USER#<user_id> | DEVICE#<token_hash> | device_token (STR), platform (IOS/ANDROID), updated_at (NUM), status (ACTIVE/INVALID) | User mobile push tokens |
TEMPLATE#<template_id> | LANG#<lang_code> | subject (STR), body_template (STR), required_vars (LIST) | Localized message templates |
Part 2: Production Deep-Dive Locked1 Coin = 24 Hours
Unlock Complete Architecture & Production Runbooks
Your Balance:40 Coins
You have explored the free architectural preview (~43%). Spend 1 Coin to unlock the remaining 6 production deep-dive sections for a full 24 hours.
Sections Included in This 24-Hour Pass:
6. Detailed Request Flow & Verification Workflows
7. Notification Architecture Trade-Off Matrix
8. Failure Modes, Resiliency & Critical Edge Cases
9. Production Pitfalls & Anti-Patterns (The "Gotchas")
10. Production Runbook & Observability Guide
11. Interview Strategy & System Design Rubric
Keeps page unlocked for exactly 24 hoursSpend coins to fund LLM & compute infrastructure