What if you could send a message once and have it instantly reach only those who care, without lifting the phone?
Why Pub/sub pattern in HLD? - Purpose & Use Cases
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.
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 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.
for subscriber in subscribers: subscriber.receive(message)
subscribers = broker.get_subscribers(topic) publisher.publish(topic, message)
It enables efficient, scalable communication where senders and receivers stay loosely connected, making systems faster and easier to manage.
News apps use pub/sub to send breaking news alerts only to users interested in specific topics, without bothering everyone with all updates.
Manual direct messaging is slow and error-prone.
Pub/sub centralizes message delivery for efficiency.
It supports scalable and flexible communication.