Pub-Sub (Publish-Subscribe)
Understand event-driven messaging with topics, publishers, and subscribers for one-to-many message distribution.
Concept snapshot
One publish, many subscribers
Publishers broadcast events to topics; every subscriber on a topic gets its own copy. Loose coupling — publishers never know who is listening.
Live fan-out
Each message delivered to every subscriber of its topic.
Publishers
Pub 1
sent 0
Topics
user-events
2 subscribers · 0 total
notifications
1 subscribers · 0 total
analytics
0 subscribers · 0 total
Subscribers
Sub 1
Sub 2
Controls
Drive the simulation
Subscribe or unsubscribe each subscriber to topics above, then publish and watch the fan-out.
Auto-publish
Manual publish
Why it matters
One-to-many, loosely coupled
What's happening
Publishers send events to a topic. Every subscriber on that topic receives its own copy — delivery fans out to all of them at once.
Why it matters
Unlike a queue (one consumer per message), Pub/Sub broadcasts to many. Publishers stay decoupled from subscribers — the model behind Kafka topics, Google Pub/Sub, and real-time notifications.
Why this exists
Pub-sub decouples event producers from event consumers through topics or streams. Producers publish once. Multiple subscribers react independently. This is powerful for event-driven systems, but requires careful thinking about ordering, replay, duplication, and consumer lag.
Fan-out is the core value
One producer can trigger analytics, notifications, search indexing, and billing without directly calling each system.
Consumers move independently
Each subscriber processes at its own speed, with its own failure handling and persistence behavior.
Events need contracts too
Loose coupling does not remove schema evolution problems. It just moves them into event design and consumer compatibility.
Key takeaways
- Pub-sub is for one-to-many event distribution.
- It reduces producer coupling, but increases event contract discipline.
- Consumer lag, replay, and ordering matter in real systems.
- Event-driven architecture is operationally powerful, not magically simpler.