Design to reduce notification frequency (product improvement + approach/tradeoffs discussion)

Difficulty: MEDIUMCategory: LLDFrequency: 1Asked On 2020-03-11

Problem Statement

Designing a system to optimize and reduce the frequency of notifications sent to users, while maintaining engagement and relevance. Focus is on backend design, data modeling, throttling strategies, and trade-offs.


✅ Functional Requirements


1.Notification Scheduling
•Track all notifications intended for a user.
•Decide whether to send immediately, batch, or delay based on user preferences and product rules.
2.Frequency Reduction Mechanisms
•Deduplication: avoid sending multiple notifications of the same type in a short window.
•Batching: combine multiple notifications into a single summary message.
•Rate-limiting / Throttling: limit notifications per user per time interval (e.g., max 5 per hour).
•Priority-based sending: critical notifications are sent immediately, non-critical can be delayed.
3.User Preferences & Personalization
•Users can configure notification frequency (e.g., daily digest, weekly summary).
•Respect opt-in/opt-out preferences.
4.Analytics & Feedback Loop
•Track notification open rates and engagement.
•Use data to adapt frequency dynamically for each user.


🔐 Constraints & Assumptions


•System handles millions of users and high notification throughput.
•Notifications can be via push, email, or SMS.
•Focus on LLD, scheduling, and frequency reduction logic, not UI/UX.


🧱 Key Components & Classes


1.Notification Class
1 2class Notification { 3public: 4 string notificationId; 5 string userId; 6 string type; // e.g., alert, reminder 7 int priority; // high, medium, low 8 DateTime createdTime; 9 bool sent; 10};
1.NotificationScheduler Class
•Manages sending notifications with frequency control.
1 2class NotificationScheduler { 3private: 4 map<string, vector<Notification>> userNotificationQueue; // per user 5 mutex schedulerMutex; 6 7public: 8 void enqueue(Notification notification); 9 void processNotifications(); // decides which notifications to send 10private: 11 bool shouldSend(Notification notification); // applies throttling, deduplication 12 void send(Notification notification); 13};
1.Frequency Control / Deduplication Module
•Encapsulates logic for rate-limiting, batching, and priority handling.


🔄 Example Workflow


1.Multiple events generate notifications → enqueue(notification) adds them to the user’s queue.
2.Scheduler runs periodically or via event → processNotifications() applies rules:
•Deduplicate similar notifications
•Batch low-priority notifications
•Apply rate limits per user
3.Notifications meeting criteria are sent → update status to sent.
4.Analytics collected for engagement → adjust rules dynamically.


🧪 Expected Deliverables


•Class diagram showing Notification, NotificationScheduler, and frequency control modules.
•Implementation of enqueue, processNotifications, shouldSend, and send methods.
•Test cases:
•Multiple notifications generated for the same user in short interval
•Deduplication works correctly
•Rate limiting enforces thresholds
•Priority notifications bypass throttling


💡 Discussion Points / Trade-offs


1.Real-time vs Batch Processing
•Real-time: immediate updates but higher resource usage.
•Batch: reduces frequency but may increase delay.
2.Memory vs Accuracy
•Keeping a full history of notifications improves accuracy but consumes memory.
•Using sliding windows or TTL caches is more memory-efficient.
3.Scalability
•Partition queues by user ID for distributed processing.
•Use message queues (Kafka, RabbitMQ) for high throughput.
4.Extensibility
•Easy to add new channels (email, push, SMS) and new throttling rules.


This problem tests LLD, modular design, rate-limiting strategies, and product-focused trade-off analysis, making it ideal for an LLD + product improvement discussion round.

Solution

Comments