Publish-Subscribe (Pub/Sub)
Also known as:
Pub/Sub
Publish Subscribe
Fan-out Messaging
Definition
Publish-subscribe is a messaging pattern where publishers send messages to a topic instead of to specific receivers, and any number of subscribers to that topic get a copy. Publishers and subscribers never know about each other, which decouples them and lets you add or remove consumers without touching the sender.
Popular reads
View All
Payment System Design: Ledger, Idempotency, and Settlement
Jul 18, 2026
X Algorithm Explained: How the Open Source Recommendation System Works
Jan 22, 2026
Cursor Skills: How to Create and Use Agent Skills
Jun 23, 2026
Complete Guide to Graph Data Structure: BFS, DFS, Adjacency List vs Matrix
Jan 20, 2026
The Complete HTMX Guide: From Zero to Production
Dec 22, 2025
Transactional Outbox Pattern: Never Lose an Event Again
Apr 07, 2026
Key Takeaways
- Publishers write to a topic, not to a consumer. This decoupling is the whole point: senders and receivers scale and change independently.
- Unlike a point-to-point message queue where one consumer gets each message, pub/sub fans one message out to many subscribers.
- It is the backbone of event-driven systems and pairs naturally with CQRS and the transactional outbox.
- You still have to decide delivery guarantees. At-least-once delivery means consumers must be idempotent to handle duplicates.
How It Works
- A publisher sends a message to a named topic on a broker.
- The broker keeps a list of subscribers for that topic.
- Each subscriber receives its own copy, either pushed to it or pulled from its own cursor in the log.
- Subscribers process independently, so a slow one does not block the others.
Where It Is Used
- Apache Kafka, Google Pub/Sub, AWS SNS, and Redis Pub/Sub are common implementations.
- Notification systems fan one event out to email, SMS, and push subscribers at once.
- Slack and other real-time apps use pub/sub to route a message to every server holding a relevant WebSocket.