Design a Notification System
4 min read- What it is: sends push (iOS/Android), SMS, and email: soft real-time, user opt-out respected
- Scale: 10M push + 1M SMS + 5M emails per day
- Key move: separate message queue per channel → one 3rd-party outage doesn't block others
- Reliability: notification log DB + retry; dedupe by event ID (exactly-once is impossible)
- Deep-dive extras: templates, opt-in settings, rate limiting,
appKey/appSecret, monitoring + events tracking
Three notification types: mobile push notification, SMS, email.

Step 1 of 4: Understand the problem and establish design scope
Goal: lock in requirements and volume.
Requirements:
- Supports push notification, SMS, and email
- Soft real-time: fast delivery, slight delay acceptable under high load
- Supported devices: iOS, Android, laptop/desktop
- Notifications triggered by client apps or scheduled server-side
- Users can opt out
- Daily volume: 10M mobile push, 1M SMS, 5M emails
Step 2 of 4: Propose high-level design and get buy-in
Goal: understand the delivery channels, then fix the initial design's SPOF with queues.
Notification types
iOS Push: provider → APNS (Apple Push Notification Service) → iOS device. Requires device token + payload (JSON).

Android Push: similar flow using Firebase Cloud Messaging (FCM).

SMS: third-party services like Twilio, Nexmo.

Email: commercial services like Sendgrid, Mailchimp.

Contact info gathering flow

When a user installs/signs up, API servers collect contact info. DB schema:

usertable: email, phone numberdevicetable: device tokens (one user → multiple devices)
Initial notification sending flow

- Services 1–N: microservices, cron jobs, etc. that trigger notifications
- Notification system: centerpiece; provides APIs, builds payloads for third-party services
- Third-party services: deliver notifications. Must be extensible (FCM unavailable in China → alternatives like Jpush, PushY)
Problems with the initial design: SPOF (single server), hard to scale independently, performance bottleneck.
Improved design

Changes:
- DB and cache moved out of the notification server
- Multiple notification servers with horizontal scaling
- Message queues decouple components: each notification type gets its own queue (outage in one third-party service doesn't affect others)
Components (left to right):
- Services 1–N: send notifications via APIs
- Notification servers: validate requests, fetch metadata from cache/DB, push events to message queues
- Cache: user info, device info, notification templates
- DB: user, notification, settings data
- Message queues: separate queue per notification type (iOS PN, Android PN, SMS, Email)
- Workers: pull events from queues, send to third-party services
API example: POST https://api.example.com/v/sms/send

Flow:
- Service calls API → 2. Notification server fetches metadata → 3. Event pushed to queue → 4. Workers pull and send → 5. Third-party delivers → 6. User receives
Step 3 of 4: Design deep dive
Goal: reliability, dedupe, and the supporting components.
Reliability
Prevent data loss: notification data persisted in a notification log DB + retry mechanism.

Exactly-once delivery? No: distributed systems can produce duplicates. Use dedupe via event ID: if the event ID was seen before, discard. (See ref [5] for why exactly-once is impossible.)
Additional components
- Notification templates: preformatted notifications with customizable parameters (item name, date, CTA). Benefits: consistent format, fewer errors, saves time
- Notification settings: users control opt-in per channel (
user_id, channel, opt_in). Check before sending - Rate limiting: cap frequency to prevent overwhelming users (excessive notifications → users disable them entirely)
- Retry mechanism: failed delivery → re-enqueue. Persistent failure → alert developers
- Security:
appKey/appSecretfor push notification APIs. Only verified clients can send - Monitor queued notifications: track total queued count. If large → add more workers

Events tracking: track open rate, click rate, engagement via analytics service integration.

Updated design

Additions: authentication + rate-limiting on notification servers, retry mechanism, notification templates, monitoring and tracking systems.
Step 4 of 4: Wrap up
Key design elements:
- Message queues for decoupling
- Robust retry mechanism
- Security via
appKey/appSecret - Tracking/monitoring at every stage
- User opt-out respect + rate limiting
[1] Twilio SMS: https://www.twilio.com/sms [2] Nexmo SMS: https://www.nexmo.com/products/sms [3] Sendgrid: https://sendgrid.com/ [4] Mailchimp: https://mailchimp.com/ [5] You Cannot Have Exactly-Once Delivery: https://bravenewgeek.com/you-cannot-have-exactly-once-delivery/ [6] Security in Push Notifications: https://cloud.ibm.com/docs/services/mobilepush [7] RabbitMQ: https://bit.ly/2sotIa6