Publish and Subscribe
Distribute an event to interested consumers with independent delivery needs.
system design, events, publish subscribeOne event, several interests
In publish/subscribe, a publisher sends an event to a topic; subscribers receive it through their own subscriptions. Unlike a single work queue where workers commonly compete for a job, fan-out gives each interested subscription its own delivery. A broker's retention and delivery policy matter.
An order has been placed
- The order service publishes an order-placed event with a stable event ID.
- Separate inventory and analytics subscriptions each receive it.
- Inventory updates stock; analytics records the order. One consumer can lag or fail while the other continues. Duplicate deliveries need safe handling.
See the reasoning
Fan an order event out
Follow independent subscriptions. This is a prepared demonstration, not live code execution.
Publish
- TopicOrder placed: event 42Current focus
- InventoryWaiting
- AnalyticsWaiting
The order service publishes an event with a stable identity.
Weather alerts
A weather publisher sends an alert to a topic. Subscribers such as a mobile notification service and a public display service each process it. Filtering by region can reduce unwanted alerts, but subscribers need expiry or superseding information so a delayed alert is not presented as current. Delivery to every device is not guaranteed by publishing to a broker.
Trade-offs and failure
Events reduce direct coupling but make tracing and schema evolution harder. Define event identity, ownership, retention, privacy and ordering scope. Consumers may see duplicates or lag; configure retries and failed-message handling. Replay is available only when the broker retains the relevant events. Publishing reliably alongside a database commit may require an outbox.
Reflect on the concept
Four fixed questions to reinforce the reasoning. Answers are not saved or scored.
