A multi-channel notification delivery system with subscription management and real-time notification tracking.
The Notification System is a low-level design implementation of a notification platform. It manages user subscriptions to channels, delivers notifications through multiple channels, tracks delivery status, and provides notification history.
- Add Users: Register users in the system
- Subscribe: Subscribe users to notification channels
- Send Notifications: Deliver to all channel subscribers
- Mark as Read: Track read status
- Get Notifications: View user notifications
- Unread Count: Get unread notification count
- History: View full notification history
- EMAIL: Email delivery
- SMS: Text message delivery
- PUSH: Push notifications
- IN_APP: In-application notifications
- LOW: Non-urgent information
- MEDIUM: Standard priority
- HIGH: Important notifications
- CRITICAL: Emergency alerts
- Singleton Pattern: Single
NotificationServiceinstance - Observer Pattern: Subscription and notification publishing
- Strategy Pattern: Different notification channels
- Notification: Individual notification record
- NotificationType: Enumeration (EMAIL, SMS, PUSH, IN_APP)
- Priority: Enumeration (LOW, MEDIUM, HIGH, CRITICAL)
- NotificationService:
- Manages users
- Handles subscriptions
- Sends notifications
- Tracks read status
- Generates reports
python main.pynotificationService = NotificationService.getInstance()
# Create users
user_id = notificationService.addUser("Alice")
# Subscribe to channel
notificationService.subscribe(user_id, "news")
# Send notification
notificationService.sendNotification(
channel="news",
message="Breaking news alert",
notification_type=NotificationType.EMAIL,
priority=Priority.HIGH
)
# Get notifications
notificationService.getUserNotifications(user_id)
# Mark as read
notificationService.markAsRead(user_id, notification_id)
# Get unread count
count = notificationService.getUnreadCount(user_id)
# View history
notificationService.getNotificationHistory(user_id)- Channel Broadcasting: Notifications sent to all channel subscribers
- Read Status: Tracks per-notification read status
- Subscription Management: Users can subscribe/unsubscribe
- Multi-channel: Same notification sent via different channels
- Priority Routing: High-priority notifications flagged
- Delivery Simulation: Prints delivery method
- History Preservation: All notifications retained
- Unread Tracking: Efficient unread counting
- User IDs auto-generated
- Notification IDs auto-generated
- Channels created on first subscription
- Channels destroyed when no subscribers
- User can subscribe multiple times (idempotent)
- Unsubscribe requires active subscription
- Notifications never deleted
- No notification expiration
- In-memory only (no persistence)
- Persistent storage
- Notification scheduling
- Delayed delivery
- Retry logic for failed deliveries
- Rate limiting per channel
- Notification templates
- Dynamic channel creation
- User notification preferences
- Frequency capping
- Do-not-disturb hours
- Rich media support
- Clickable actions in notifications
- Notification groups
- Read receipts
- Delivery status tracking
- A/B testing
- Analytics and reporting
- Webhook integrations
- Third-party providers (Twilio, SendGrid)
| Type | Method | Use Case |
|---|---|---|
| Long-form notifications | ||
| SMS | Text Message | Urgent alerts |
| PUSH | App Push | Mobile notifications |
| IN_APP | In-application | User interface alerts |
| Level | Use Case | Response Time |
|---|---|---|
| LOW | Newsletter | Non-urgent |
| MEDIUM | Standard | Normal processing |
| HIGH | Important | Fast |
| CRITICAL | Emergency | Immediate |
- Add User: O(1)
- Subscribe: O(1)
- Send Notification: O(s) where s = subscribers
- Mark as Read: O(1)
- Get Unread Count: O(n) where n = notifications
- Get Notifications: O(n)
- Get History: O(n)
- O(u + c + n) where u = users, c = channels, n = notifications