Design notification system for Google Docs
Difficulty: MEDIUMCategory: LLDFrequency: 1Asked On 2022-02-11
Problem Statement
Design a system that sends real-time and periodic notifications to users of Google Docs regarding document updates, comments, sharing events, or edits. The focus is on object-oriented design, modularity, and efficient delivery of notifications.
✅ Functional Requirements
1.Notification Types
•Edit Notifications: Notify users when a document they have access to is edited.
•Comment Notifications: Notify users about comments or replies.
•Sharing Notifications: Notify users when documents are shared or access changes.
•Periodic Digest (Optional): Daily/weekly summary of document activity.
2.User Preferences
•Users can opt-in or opt-out of certain notification types.
•Support notification channels: email, push notifications, in-app notifications.
3.Event Handling
•Capture events from Google Docs: edit, comment, share.
•Map events to the appropriate recipients based on document access control.
•Queue and deliver notifications asynchronously.
4.Delivery Guarantees
•Ensure notifications are delivered at least once.
•Handle retries and failures.
5.Optional Features
•Batch notifications to reduce spam.
•Real-time notifications using WebSockets or push protocols.
•Logging and analytics for delivered and failed notifications.
🔐 Constraints & Assumptions
•Focus is on LLD, notification workflow, and modular components, not on full Google Docs implementation.
•Assume user access control and document metadata are available from the document service.
•The system should be scalable to millions of users.
🧱 Key Components & Classes
1.Event Class
1
2class Event {
3private:
4 string eventId;
5 string eventType; // EDIT, COMMENT, SHARE
6 string documentId;
7 string triggeredByUserId;
8 DateTime timestamp;
9public:
10 string getEventType();
11 string getDocumentId();
12};1.Notification Class
1
2class Notification {
3private:
4 string notificationId;
5 string userId;
6 string documentId;
7 string type; // EDIT, COMMENT, SHARE
8 string message;
9 DateTime timestamp;
10public:
11 void send();
12};1.UserPreferences Class
1
2class UserPreferences {
3private:
4 string userId;
5 bool emailEnabled;
6 bool pushEnabled;
7 bool inAppEnabled;
8public:
9 bool isEnabled(string notificationType, string channel);
10};1.NotificationManager Class
1
2class NotificationManager {
3private:
4 EventQueue* eventQueue;
5 UserPreferencesService* preferencesService;
6public:
7 void handleEvent(Event event);
8 void deliverNotification(Notification notification);
9};1.EventQueue Class
1
2class EventQueue {
3private:
4 queue<Event> queue;
5 mutex queueMutex;
6public:
7 void enqueue(Event event);
8 Event dequeue();
9};1.DeliveryService Class
•Sends notifications via email, push, or in-app.
•Handles retries and failure logging.
🔄 Example Workflow
1.A user edits a document → Event is created with eventType=EDIT.
2.NotificationManager.handleEvent() fetches document collaborators.
3.For each recipient, check UserPreferences.
4.Create Notification object and send via DeliveryService.
5.Retry or log failures if delivery fails.
🧪 Expected Deliverables
•Class diagram showing Event, Notification, NotificationManager, EventQueue, and UserPreferences.
•Implementation of event handling, notification generation, and delivery.
•Test cases:
•Edit event notification
•Comment notification
•Share notification
•User with multiple channels and preferences
•Retry mechanism on failure
💡 Discussion Points
•Scalability: event queues, batching, and worker threads.
•Delivery guarantees: at least once, eventual consistency.
•Optional: real-time notifications using WebSockets.
•Extensibility for group notifications or digest emails.