When to reach for it
- Many agents or services are loosely coupled.
- Events go to multiple receivers.
- Extensibility without central dependencies is important.
/pattern/pubsub-mesh/
Agents publish to and subscribe to named topics on a shared bus instead of calling each other directly, so a publisher never knows who consumes its events and subscribers can be added or removed without touching the publisher.
In practiceA sensor-monitoring platform publishes `anomaly.detected` events on a shared bus; three independent agents — alerting, logging, and auto-remediation — each subscribe and react independently without knowing about each other.
When to reach for it
When it backfires
The tradeoff
Scalable decoupling is gained against more complex delivery, debugging, and governance.
Messages fan out to all interested subscribers.
Topics are coined ad-hoc; near-synonyms multiply; agents subscribe to one and miss messages published to the other. The naming is the system's bug surface.
Fix · Centralise topic definitions in a registry with descriptions and ownership. Reject publishes to unregistered topics at the broker.
The bus redelivers an event after a consumer ack times out. A non-idempotent handler runs the side effect twice — a second charge, a duplicate order, a doubled metric.
Fix · Make handlers idempotent keyed by event id, and dedupe within a window at the consumer; never assume exactly-once from the broker.
Keep going
Search patterns, frameworks, and pages.