What Is the Pub/Sub Pattern?
Publish/Subscribe (pub/sub) is a messaging pattern where publishers send messages to a named channel without knowing who (if anyone) is listening, and subscr...
Published October 9, 2026
In the publish/subscribe pattern, publishers send messages to named topics without knowing who is listening, and subscribers receive messages for the topics they chose. A broker sits in the middle and fans messages out.
The concept
Publishers and subscribers are fully decoupled: neither knows the other exists. New subscribers can be added without changing publishers.
Used in event-driven systems, notifications and real-time apps (Redis Pub/Sub, Kafka, Google Pub/Sub, MQTT).
One message, many receivers
Practical examples
Redis
SUBSCRIBE order.created
PUBLISH order.created '{"id":7}'Node
sub.subscribe('order.created')
sub.on('message', (ch, msg) => sendEmail(JSON.parse(msg)))
pub.publish('order.created', JSON.stringify({ id: 7 }))Topic naming
orders.created · orders.cancelled · users.registeredCommon mistakes
- Assuming Redis Pub/Sub stores messages — offline subscribers miss them.
- Tight coupling through message shapes with no versioning.
- No dead-letter handling.
Key takeaways
- Topics decouple senders and receivers.
- One-to-many delivery.
- Choose a broker with the durability you need.
FAQ
Pub/Sub vs message queue?
Queues deliver each message to one worker; pub/sub delivers to all subscribers.
Observer vs Pub/Sub?
Observer is direct; pub/sub goes through a broker.