Reading preferences
Concept

Publish and Subscribe

Distribute an event to interested consumers with independent delivery needs.

system design, events, publish subscribe

One 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

  1. The order service publishes an order-placed event with a stable event ID.
  2. Separate inventory and analytics subscriptions each receive it.
  3. 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

One published event, two consumers
  1. TopicOrder placed: event 42Current focus
  2. InventoryWaiting
  3. 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.

1. What does a publisher send?
2. Why use separate subscriptions for inventory and analytics?
3. Can every new subscriber replay old events?
4. What should a subscriber assume about ordering?

References and further reading