0
0
HLDsystem_design~12 mins

Pub/sub pattern in HLD - Architecture Diagram

Choose your learning style9 modes available
System Overview - Pub/sub pattern

The Pub/Sub pattern is a messaging architecture where publishers send messages without knowing who will receive them. Subscribers express interest in certain message topics and receive only those messages. This decouples message producers from consumers, enabling scalable and flexible communication.

Architecture Diagram
User Publisher
    |
    v
+-----------------+
|  Message Broker |
+-----------------+
    ^       ^
    |       |
Subscriber1 Subscriber2
Components
User Publisher
publisher
Sends messages to the message broker on specific topics
Message Broker
message_broker
Receives messages from publishers and routes them to subscribers based on topic subscriptions
Subscriber1
subscriber
Receives messages from the broker for subscribed topics
Subscriber2
subscriber
Receives messages from the broker for subscribed topics
Request Flow - 3 Hops
User PublisherMessage Broker
Message BrokerSubscriber1
Message BrokerSubscriber2
Failure Scenario
Component Fails:Message Broker
Impact:Messages cannot be routed; publishers cannot deliver messages; subscribers receive no updates
Mitigation:Use broker clustering with failover and replication to ensure availability and message durability
Architecture Quiz - 3 Questions
Test your understanding
In the Pub/Sub pattern, who decides which subscribers receive a message?
ASubscribers pull messages from the Publisher
BThe Message Broker based on topic subscriptions
CThe Publisher directly sends to subscribers
DA Load Balancer distributes messages randomly
Design Principle
The Pub/Sub pattern decouples message producers and consumers by introducing a message broker that routes messages based on topics. This enables scalable, flexible, and asynchronous communication where publishers and subscribers do not need to know about each other directly.