0
0
LLDsystem_design~7 mins

Notification to all parties in LLD - System Design Guide

Choose your learning style9 modes available
Problem Statement
When an important event occurs, failing to notify all relevant parties causes confusion, delays, and errors. Without a reliable way to send notifications to everyone involved, some users may miss critical updates, leading to poor coordination and reduced trust in the system.
Solution
This pattern ensures that when an event happens, the system sends notifications to all registered parties automatically. It works by maintaining a list of subscribers and broadcasting messages to each one, either synchronously or asynchronously, so everyone stays informed in real time or near real time.
Architecture
Event
Notification
Subscriber 2
Subscriber N
Subscriber N

This diagram shows an event source triggering a notification dispatcher that sends messages to multiple subscribers.

Trade-offs
✓ Pros
Ensures all interested parties receive timely updates.
Decouples event generation from notification delivery, improving modularity.
Supports multiple notification channels (email, SMS, push) easily.
Can scale by adding more subscribers without changing event source.
✗ Cons
Requires managing subscriber lists and handling failures in delivery.
Can introduce latency if notifications are sent synchronously.
Complexity increases with multiple notification channels and formats.
Use when multiple users or systems must be informed about events, especially if the number of subscribers is moderate to large (hundreds to thousands).
Avoid if only one or two parties need notification or if notifications are not critical, as overhead may outweigh benefits.
Real World Examples
Uber
Uber notifies drivers and riders simultaneously about trip status changes to keep both parties updated in real time.
Amazon
Amazon sends order status notifications to customers, warehouse staff, and delivery partners to coordinate fulfillment.
Slack
Slack broadcasts message notifications to all members of a channel to ensure everyone sees updates promptly.
Code Example
The before code shows an event happening with no notifications sent. The after code introduces a NotificationDispatcher that keeps a list of subscribers and sends them messages when an event occurs. Subscribers implement an update method to receive notifications. This pattern ensures all parties are informed automatically.
LLD
### Before: No notification to all parties
class EventSource:
    def event_occurred(self):
        print("Event happened")

source = EventSource()
source.event_occurred()


### After: Notify all subscribers
class NotificationDispatcher:
    def __init__(self):
        self.subscribers = []

    def subscribe(self, subscriber):
        self.subscribers.append(subscriber)

    def notify_all(self, message):
        for subscriber in self.subscribers:
            subscriber.update(message)

class Subscriber:
    def __init__(self, name):
        self.name = name

    def update(self, message):
        print(f"{self.name} received notification: {message}")

class EventSource:
    def __init__(self, dispatcher):
        self.dispatcher = dispatcher

    def event_occurred(self):
        message = "Event happened"
        self.dispatcher.notify_all(message)

# Setup
dispatcher = NotificationDispatcher()
dispatcher.subscribe(Subscriber("Subscriber 1"))
dispatcher.subscribe(Subscriber("Subscriber 2"))

source = EventSource(dispatcher)
source.event_occurred()
OutputSuccess
Alternatives
Polling
Subscribers repeatedly check for updates instead of receiving push notifications.
Use when: Choose polling when real-time updates are not critical and system simplicity is preferred.
Webhook callbacks
System calls subscriber endpoints directly on events rather than broadcasting internally.
Use when: Choose webhooks when integrating with external systems that require immediate event data.
Summary
Notification to all parties ensures every interested user or system receives event updates automatically.
It works by maintaining subscriber lists and sending messages to each when events occur.
This pattern improves coordination and reduces missed information in multi-party systems.