0
0
LLDsystem_design~25 mins

Notification to all parties in LLD - System Design Exercise

Choose your learning style9 modes available
Design: Notification to All Parties System
Design covers notification sending, scheduling, retry, and status tracking. Does not cover user management or content creation for notifications.
Functional Requirements
FR1: Send notifications to multiple parties (users, admins, external systems) simultaneously
FR2: Support multiple notification channels: email, SMS, push notifications
FR3: Allow scheduling notifications for future delivery
FR4: Provide delivery status tracking for each notification
FR5: Support retry mechanism for failed notifications
FR6: Allow priority levels for notifications (high, medium, low)
FR7: Handle up to 100,000 notifications per hour
FR8: Ensure notifications are delivered within 5 seconds for real-time messages
Non-Functional Requirements
NFR1: System must be highly available with 99.9% uptime
NFR2: Latency for sending notifications should be under 5 seconds for real-time notifications
NFR3: Support horizontal scaling to handle increased load
NFR4: Ensure data privacy and security for user contact information
NFR5: Design must be modular to add new notification channels easily
Think Before You Design
Questions to Ask
❓ Question 1
❓ Question 2
❓ Question 3
❓ Question 4
❓ Question 5
❓ Question 6
❓ Question 7
Key Components
API Gateway or Notification Request Handler
Notification Scheduler
Message Queue for decoupling
Notification Dispatcher for each channel
Delivery Status Tracker
Database for storing notification metadata and status
Retry Mechanism
Monitoring and Alerting
Design Patterns
Publish-Subscribe pattern for distributing notifications
Queue-based asynchronous processing
Circuit Breaker for external channel failures
Bulkhead pattern to isolate failures
Priority Queue for handling notification priorities
Reference Architecture
  +-------------------+       +------------------+       +---------------------+
  | Notification      |       | Notification     |       | Notification        |
  | Request Handler   | ----> | Scheduler        | ----> | Message Queue       |
  +-------------------+       +------------------+       +---------------------+
                                                                |
                                                                v
  +---------------------+    +---------------------+    +---------------------+
  | Email Dispatcher    |    | SMS Dispatcher      |    | Push Notification   |
  | (SMTP or API)       |    | (SMS Gateway API)   |    | Dispatcher          |
  +---------------------+    +---------------------+    +---------------------+
            |                        |                          |
            v                        v                          v
  +---------------------+    +---------------------+    +---------------------+
  | Delivery Status     |    | Delivery Status     |    | Delivery Status     |
  | Tracker DB          |    | Tracker DB          |    | Tracker DB          |
  +---------------------+    +---------------------+    +---------------------+

  Retry Mechanism monitors failures and resubmits messages.

  Monitoring & Alerting watches system health and failures.
Components
Notification Request Handler
REST API Server (Node.js/Express or Python Flask)
Receives notification requests from clients and validates them
Notification Scheduler
Scheduler Service (Cron jobs or Quartz Scheduler)
Schedules notifications for immediate or future delivery
Message Queue
RabbitMQ or Apache Kafka
Decouples request handling from notification dispatching for scalability
Notification Dispatchers
Separate microservices for Email, SMS, Push (using SMTP, Twilio API, Firebase Cloud Messaging)
Send notifications through respective channels
Delivery Status Tracker
Relational DB (PostgreSQL) or NoSQL (MongoDB)
Stores notification metadata and delivery status updates
Retry Mechanism
Background worker or scheduled job
Retries failed notifications based on configurable policies
Monitoring and Alerting
Prometheus + Grafana or Cloud monitoring tools
Tracks system health, failures, and performance metrics
Request Flow
1. Client sends notification request to Notification Request Handler via REST API.
2. Request Handler validates and stores notification metadata in DB.
3. If scheduled for future, Notification Scheduler queues the notification at the right time.
4. Notification Scheduler pushes notification message to Message Queue.
5. Notification Dispatchers consume messages from the queue based on channel type.
6. Dispatchers send notifications via external services (SMTP, SMS gateway, push service).
7. Dispatchers update Delivery Status Tracker with success or failure.
8. Retry Mechanism monitors failures and resubmits messages to the queue.
9. Monitoring system collects metrics and alerts on failures or delays.
Database Schema
Entities: - Notification: id (PK), content, channel, priority, scheduled_time, created_at - Recipient: id (PK), notification_id (FK), party_id, contact_info - DeliveryStatus: id (PK), recipient_id (FK), status (pending, sent, failed), last_attempt_time, retry_count Relationships: - Notification 1:N Recipient - Recipient 1:1 DeliveryStatus
Scaling Discussion
Bottlenecks
Message Queue throughput limits under high load
Notification Dispatchers overwhelmed by large volume
Database write/read bottlenecks for delivery status tracking
Retry mechanism causing duplicate or delayed notifications
External channel rate limits or failures
Solutions
Partition or shard message queues; use multiple queues per channel or priority
Scale dispatchers horizontally with load balancing
Use database sharding or caching for delivery status; consider NoSQL for high write throughput
Implement idempotency and exponential backoff in retry logic
Use circuit breakers and fallback channels; monitor external service limits
Interview Tips
Time: Spend 10 minutes understanding requirements and clarifying scope, 20 minutes designing components and data flow, 10 minutes discussing scaling and trade-offs, 5 minutes summarizing.
Clarify notification channels and delivery guarantees
Explain asynchronous processing with message queues
Discuss retry and failure handling strategies
Highlight modular design for adding new channels
Address scaling challenges and solutions
Mention security and privacy considerations