Build Your Own Notification Engine | System Design
Welcome to the LLD Series: Designing a Notification System
Introduction to Notification Systems
- The lecture introduces the concept of designing a notification system, which is frequently asked in interviews.
- A notification system integrates with applications to send notifications via various channels like SMS, email, or WhatsApp.
- It emphasizes understanding how a notification service works and its design structure during interviews.
Requirements for the Notification System
- The first requirement is to create a "plug-and-play" model that allows easy integration into any application without major code changes.
- The notification service must be highly extendable, allowing future additions like WhatsApp notifications without significant code alterations.
- Following SOLID design principles is crucial for ensuring extensibility and maintainability of the system.
Features of the Notification Service
- The service should allow dynamic feature addition, such as headers and footers in notifications.
- All notifications must be stored and logged for record purposes; initially logging can be done on the console.
Functional and Non-functional Requirements
- It's important to clarify both functional and non-functional requirements with interviewers for clear scope definition.
UML Diagram and Design Structure
- Starting with a UML diagram helps visualize how the design will evolve while adhering to design principles.
Creating the Notification Class
Initial Class Design
- A
Notificationclass is created as an abstract class that defines methods for concrete classes implementing specific types of notifications.
Naming Conventions
- Abstract classes are prefixed with 'I' (e.g.,
INotification) to indicate they serve as interfaces.
Implementing Concrete Notifications
Simple Notification Implementation
- A simple notification type takes a text string as content, returning it through an overridden method called
getContent.
Extending Notifications
- Future extensions could include HTML notifications that allow richer content formats beyond plain text.
Dynamic Feature Addition Using Decorator Pattern
Utilizing Decorators
- To enable dynamic feature addition, decorators are used. This allows adding features like signatures or timestamps without altering existing code structures.
Building Concrete Decorators
Creating Specific Decorators
- Two concrete decorators are introduced:
TimestampDecoratorandSignatureDecorator, each enhancing the base notification's functionality by overridinggetContent.
Observer Pattern Integration
Implementing Observables
- An observable pattern is established where observers wait for new notifications. This pattern suits scenarios where multiple observers need updates about new events.
Developing Observable Classes
Abstract Observable Creation
- An abstract observable class (
IObservable) manages observer lists with methods like add, remove, and notify.
Concrete Observable Implementation
Defining Concrete Observables
NotificationObservableimplements methods from its abstract counterpart by managing observer interactions effectively.
Observer Classes Development
Logger as an Observer
- A logger observer captures incoming notifications when pushed by observables. It logs these messages onto the console initially but can be extended later.
Introducing Notification Engine
Functionality Overview
- The notification engine sends out alerts via different channels (SMS, email). It acts based on strategies defined within its architecture.
Strategy Pattern Application
Strategy Definition
- A strategy interface (
INotificationStrategy) outlines sending mechanisms while concrete implementations handle specifics per channel (email/SMS/popup).
Finalizing Strategies
Implementing Channel-Specific Strategies
- Each strategy knows how to send messages through its respective medium using predefined logic tailored for emails or SMS delivery systems.
Integrating Everything Together
Complete Architecture Overview
- The entire architecture combines all components: creating notifications, applying decorators dynamically, notifying observers efficiently while maintaining historical records through services designed as singletons.
Overview of Notification Service Design
Plug and Play Model
- The notification service is designed as a plug-and-play model, allowing clients to integrate it easily without needing to understand the internal workings.
- Clients can simply call a 'send notification' method, while the entire flow is managed internally by the service.
Extensibility and Strategy
- The notification service supports various channels like SMS, email, and pop-ups, with strategies in place for future extensions.
- A decorator pattern is utilized to allow dynamic changes in notifications, enhancing flexibility in how notifications are structured.
Notification Hierarchy
- A clear hierarchy exists within the notification system that includes observers and strategies alongside a singleton notification service class.
- Initial implementations involve creating basic notifications with methods such as 'get content', which returns simple text.
Decorators Implementation
- Two types of concrete decorators were created: timestamp decorator adds timestamps to notifications; signature decorator appends user signatures.
- The timestamp decorator modifies the get content method to include current time information dynamically.
Observer Pattern Components
- An IObserver interface was established with an update method for notifying observers about changes.
- An Observable interface was created with methods for adding, removing, and notifying observers regarding updates on notifications.
Concrete Implementations of Observers
Concrete Observable Class
- A concrete observable class manages a list of observers and holds current notifications for distribution when updates occur.
Adding Observer Functionality
- Methods for adding and removing observers were implemented without validation checks initially; this allows straightforward integration into existing systems.
Logger Implementation
- A logger observer logs new notifications received from the observable without altering their content or structure.
Notification Strategies
Strategy Interface Creation
- An INotificationStrategy interface defines a single method 'send notification' that handles different types of message delivery (SMS, email).
Specific Strategies Developed
- Three specific strategies were developed: Email strategy sends messages via email; SMS strategy sends messages via mobile numbers; Popup strategy displays instant alerts without additional parameters.
Singleton Notification Service
Singleton Design Pattern
- The main notification service follows the singleton design pattern ensuring only one instance exists throughout application lifecycle.
Core Functionalities
- Key functionalities include storing all sent notifications for history tracking and providing an observable instance for client interactions.
Client Interaction Flow
Simplified Client Integration
- Clients interact with the notification service through simplified calls without needing detailed knowledge about observables or observers.
Updated Code Structure
- Recent code updates allow loggers to automatically retrieve observables from the notification service upon instantiation simplifying client-side implementation significantly.
Turn any video into a summary like this
YouTube links, meetings, lectures. With transcripts, search, and chat.





