Concurrent Real-Time Notification System

Difficulty: MEDIUMCategory: HLDFrequency: 1Asked On 2025-02-07

Problem Statement

Design a real-time notification system (similar to those used by WhatsApp, Slack, or Google Docs) that can reliably deliver notifications (push, email, in-app) to millions of users concurrently with low latency. The system must handle high throughput, retries, personalization, and concurrency across multiple devices per user.


Functional Requirements


1.Notification Types
•Support in-app, push, SMS, email notifications.
•Allow configurable channels per user.
2.Real-Time Delivery
•Deliver notifications in < 1 second latency.
•Ensure ordering of notifications when required (per user or per conversation).
3.Concurrent Handling
•Multiple notifications can be generated simultaneously for a large user base.
•A user can receive notifications across multiple devices (phone, web, tablet).
4.Retry & Reliability
•Retry on failures (e.g., push server down).
•Guarantee at-least-once delivery.
5.Personalization
•Allow filtering based on user preferences (e.g., mute chat, email only).
6.Scalability
•Should handle millions of concurrent notifications at peak.


Non-Functional Requirements


•High Throughput → Must scale horizontally to support millions of messages per second.
•Low Latency → Notifications must be near real-time.
•Fault Tolerance → Handle server crashes, retries, and queue failures gracefully.
•Durability → Persist notifications until successfully delivered.
•Monitoring & Metrics → Track delivery success, latency, and retry counts.


Design Considerations


•Producers → Event sources (chat messages, comments, system alerts).
•Queueing Layer → Kafka/Pulsar/RabbitMQ for buffering and decoupling producers-consumers.
•Notification Service (workers):
•Reads from queue.
•Applies user preferences, throttling, and deduplication.
•Sends to downstream channel (APNs, FCM, Email Gateway, SMS).
•Database → User preferences, notification templates, delivery logs.
•Delivery APIs → Integrate with Apple Push Notification Service (APNs), Firebase Cloud Messaging (FCM), SES, Twilio, etc.
•Concurrency → Thread pools, async workers, and horizontal scaling of services.
•Backpressure & Rate Limiting → Protect downstream systems.


Example HLD Components


•Event Producers → Chat Service, Activity Feed, Monitoring Alerts.
•Message Queue → Kafka for scaling and durability.
•Notification Dispatcher → Stateless microservices handling business logic.
•Channel Adapters → Push Adapter, Email Adapter, SMS Adapter.
•User Profile Service → Stores preferences, muted settings.
•Delivery Store → Logs notification status, retry attempts.
•Monitoring → Prometheus + Grafana for system health.


Solution

Comments