frameworkEngineering & architecture

Publish–Subscribe

A messaging pattern in which publishers send to a topic and each interested subscription receives its own copy.

Download Markdown (.md)

01What it means

Publish–subscribe, or pub/sub, is a messaging pattern that separates publishers from subscribers through named topics or channels. A publisher emits a message without addressing individual receivers; the messaging system distributes it to each matching subscription. Unlike competing consumers on one queue, separate subscriptions can each receive the same publication.[1][2]

One publication, independent subscriptions Publishers address a topic; each subscription receives the message
Publishers
Publisher APublisher B
Topic or channel
Named topic
Subscriptions
Subscription 1Subscription 2Subscription 3
Subscribers
Consumer AConsumer BConsumer C

Separate subscriptions can each receive the same publication.

02Why it matters

One product event can drive independent capabilities such as notifications, analytics, fulfillment, and auditing without the producer calling each system. New subscribers can be added with less producer change, although every subscriber still depends on the event's meaning and delivery behavior.

03When to use it

Use pub/sub when multiple independent consumers should react to the same event or data stream. Use a work queue when one of several workers should perform each task, and use a direct request when the publisher needs an immediate response from a known receiver.

04How it works

  1. Define a stable topic and message contract representing a meaningful event or update.
  2. Publishers send messages to the topic without selecting individual subscribers.
  3. Each consumer creates or uses a subscription with any supported filters and retention policy.
  4. The messaging service copies or exposes matching messages to every subscription.
  5. Subscribers acknowledge and process deliveries independently, handling duplicates and failures.
  6. Teams monitor subscriber lag, failed delivery, schema compatibility, and business completion.

05A practical example

Example

After an order is accepted, the order service publishes one event. Separate subscriptions trigger fulfillment, customer messaging, fraud review, and analytics. A temporary analytics failure builds lag only on its subscription and does not block fulfillment.

06Where it breaks

Pub/sub introduces asynchronous timing, duplicate or out-of-order delivery, and harder end-to-end tracing. Slow subscribers may accumulate costly backlogs, and a loosely governed topic can become an unstable integration contract shared by many teams.

Common mistakes

  • Using one shared queue when every consumer actually needs its own copy.
  • Publishing vague events whose meaning changes with the producer's internal model.
  • Assuming publication means all subscribers completed their work.
  • Ignoring slow, inactive, or repeatedly failing subscriptions.

07Sources

  1. Publish-Subscribe PatternAWS Prescriptive Guidance · Institutional architecture guidePublish-Subscribe Pattern
  2. Pub/Sub OverviewGoogle Cloud · Official technical documentationPub/Sub Overview
View saved topics

Start typing to search titles, definitions, categories, and frameworks.