Standalone conceptPatternChapter II · Communication · Building block 8 of 23

Publish-Subscribe

Pub/sub fans one event out into independent deliveries.

  1. PublisherPublishes a business fact without a receiver list.
  2. SubscriptionCreates its own delivery and filter rule.
  3. CompatibilityAllows schema changes for independently deployed consumers.

Context

Why this is important

Decoupling succeeds only when each subscriber owns lag, failures, and compatibility.

The distributed subscribers are hypothetical; the current shop has seven modules in one process.

Shop example · Mapping

Compare messaging forms

In the current shop, seven modules run together. Hypothetically, Order publishes OrderPaid after confirmed payment. Shipping, Customer Notification, and Analytics each receive a delivery through separate subscriptions and retain their own position and failures. The team takes Analytics offline, publishes more events, and proves that Shipping progresses, Analytics catches up, and duplicate delivery causes no duplicate business effect.

This is how you read the picture

  1. Publisher Event rather than command
  2. Subscription Lag per receiver group
  3. Compatibility Prefer additive evolution
Compare messaging forms
ComparisonFormDistributionHistory
QueueOne job to one consumerCompeting workersUntil ack or expiry
Pub/subOne delivery per subscriptionIndependent receiver groupsPer broker contract
Event StreamReader position per groupReplay possibleDefined retention
Receiver count and replayability distinguish the contracts.

Benefits & limitations

Helps if:

  • Several independent reactions follow the same event.
  • Publishers should accept new receivers without changes.
  • Delayed processing is acceptable.

Boundaries

  • New subscribers do not see earlier events without retained history.
  • Global ordering across subscribers is usually not guaranteed.
  • An event does not replace an atomic transaction across publisher and receivers.

In practice

  1. Publish OrderPaid and track receipt status separately for shipping, analytics, and customer communications. Check that no subscriber takes over another’s work.
  2. Stop only the analytics subscriber and watch its backlog. Confirm shipping continues and analytics later catches up from its own position.
  3. Compare Pub/Sub with queue distribution when every subscriber must receive the message. Assess recipient coupling, retention, and replay.
Read the detailed explanation

The publisher describes an event that happened and addresses no specific receiver. The broker evaluates subscriptions and filters and creates an independent delivery for every matching consumer group.

A slow subscriber must not block others but creates its own backlog. Schema changes must remain compatible with independently deployed receivers; redelivery requires idempotency per subscription.

Queue distributes one work item to one consumer. Event Stream retains a replayable sequence with position and retention.

Check your understanding

Test yourself in three stages

  1. ReadingCheck in the picture

    How many deliveries does a matching event create?

    View the solution with justification

    One per matching subscription or consumer group.

  2. ApplyingTransferred to a new situation

    Why does the Analytics outage not block Shipping?

    View the solution with justification

    They own separate subscriptions and backlogs.

  3. EvaluateWeighing an alternative

    When is an event stream preferable?

    View the solution with justification

    When later readers must replay historical events from their own position.

Continue on the learning path

Next in Communication & APIs: Queue.

23 Building blocks

Continue withQueue