0
0
HLDsystem_design~3 mins

Why Pub/sub pattern in HLD? - Purpose & Use Cases

Choose your learning style9 modes available
The Big Idea

What if you could send a message once and have it instantly reach only those who care, without lifting the phone?

The Scenario

Imagine a busy office where every employee must call each other individually to share updates. If one person has news, they must dial every colleague's number and explain it one by one.

The Problem

This manual calling is slow, tiring, and easy to forget someone. Important messages get delayed or lost, and the office becomes chaotic with repeated calls and confusion.

The Solution

The Pub/sub pattern acts like a central bulletin board where anyone can post messages, and those interested can read them instantly. No need to call everyone; messages reach the right people automatically.

Before vs After
Before
for subscriber in subscribers:
    subscriber.receive(message)
After
subscribers = broker.get_subscribers(topic)
publisher.publish(topic, message)
What It Enables

It enables efficient, scalable communication where senders and receivers stay loosely connected, making systems faster and easier to manage.

Real Life Example

News apps use pub/sub to send breaking news alerts only to users interested in specific topics, without bothering everyone with all updates.

Key Takeaways

Manual direct messaging is slow and error-prone.

Pub/sub centralizes message delivery for efficiency.

It supports scalable and flexible communication.