Design Notification System
3 min readDec 10, 2023
The Notification System alerts users with important information, including breaking news, product updates, events, offerings, etc. Notifications can be delivered through mobile push notifications, SMS messages, or emails.
Functional Requirements:
- Different types of notifications (SMS, Email, Mobile Push)
- Real-Time System (A slight delay is acceptable)
- Subscription (User can opt-in/opt-out)
Non-Functional Requirements:
- Highly Scalable (Sends out millions of notifications in a day.)
- Supports multiple Devices (IOS, Android, Laptop/Desktop)
- Reliable
Types of Notification:
- SMS
- Mobile Push (IOS, Android)
Notification Component:
- Provider: Build and Send notification to notification service.
- Device Token: Unique Identifier used for sending push notifications.
- Payload: JSON, contains notification payload.
- Notification Service: Sends notifications to clients.
- Client (Mobile Devices/Emails)
IOS Push Notification:
APNs: Apple Push Notification Service, a remote service Apple provides to propagate push notifications to IOS.
Android Push Notification:
FCM: Firebase Cloud Messaging sends push notifications to Android devices.
SMS Message:
Email:
Notification Flow:
Contact Gathering Flow:
Gather mobile device tokens, phone numbers, or email addresses. When users install apps or sign up for the first time, API servers collect user contact info and store it in the database.
DB Design:
High-Level Flow:
Design Deep Dive:
Reliability:
- Prevent Data Loss: Persists notification data in the database and implements a retry mechanism.
- Deliver notification exactly once: Due to the distributed nature could result in duplicate notifications. Use cache DB to check if the event(EventID) has been seen before or not.
Raw Design:
Services:
- Service 1 to N (Providers): Microservice, a cron job or a distributed system that triggers notification-sending events.
- Notification Systems/Servers: Provide APIs to send notifications. Do validations to verify emails, phone numbers etc. Put notification data into the message Queue.
- Cache: User Info, device info, and notification templates are cached.
- DB: It stores data about users, notifications, settings, etc.
- Message Queues: Buffers when high volumes of notifications are to be sent out. They remove dependencies between components.
- Workers: List of servers that pull notification events from message queues and send them to the corresponding third-party services.
- Third-Party Services: APNs, FCM, SMS, Emails etc.
- Notification Log: To prevent data loss, persist notification data in a database.
- Notification Template: Preformatted notification to create unique notifications by customizing parameters, styling, tracking links, etc.
- Notification Setting: User-based setting to Opt In/Opt Out notification settings.
- Rate Limiting: Limit the number of notifications a user can receive.
- Retry Mechanism: When a third-party service fails to send a notification, the notification will be added to the message queue for retrying.
- Analytics Service: Used for events tracking, such as open rate, click rate and engagements to understand customer behaviours.
High-Level Architecture:
ThankYou. Please do give suggestions.