Skip to content

Latest commit

 

History

History

Folders and files

NameName
Last commit message
Last commit date

parent directory

..
 
 
 
 
 
 
 
 

README.md

Notification System

A multi-channel notification delivery system with subscription management and real-time notification tracking.

Overview

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.

Features

Core Functionality

  • 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

Notification Channels

  • EMAIL: Email delivery
  • SMS: Text message delivery
  • PUSH: Push notifications
  • IN_APP: In-application notifications

Priority Levels

  • LOW: Non-urgent information
  • MEDIUM: Standard priority
  • HIGH: Important notifications
  • CRITICAL: Emergency alerts

Architecture

Design Patterns

  • Singleton Pattern: Single NotificationService instance
  • Observer Pattern: Subscription and notification publishing
  • Strategy Pattern: Different notification channels

Components

Models

  • Notification: Individual notification record
  • NotificationType: Enumeration (EMAIL, SMS, PUSH, IN_APP)
  • Priority: Enumeration (LOW, MEDIUM, HIGH, CRITICAL)

Services

  • NotificationService:
    • Manages users
    • Handles subscriptions
    • Sends notifications
    • Tracks read status
    • Generates reports

Usage

python main.py

Example Workflow

notificationService = 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)

Key Implementation Details

  • 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

Constraints & Assumptions

  • 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)

Possible Enhancements

  • 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)

Notification Channels

Type Method Use Case
EMAIL Email Long-form notifications
SMS Text Message Urgent alerts
PUSH App Push Mobile notifications
IN_APP In-application User interface alerts

Priority Levels

Level Use Case Response Time
LOW Newsletter Non-urgent
MEDIUM Standard Normal processing
HIGH Important Fast
CRITICAL Emergency Immediate

Time Complexity

  • 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)

Space Complexity

  • O(u + c + n) where u = users, c = channels, n = notifications