NEW
Also known as: Pub/Sub
A messaging pattern where publishers emit events to topics and subscribers receive relevant events without direct knowledge of each other.
DESCRIPTION
Publish-subscribe decouples message producers from consumers via an intermediary, typically a broker. Publishers send messages to topics; subscribers receive copies of relevant messages. This supports fan-out, scalability, and loose coupling. It is central to event-driven architectures and stream processing. Variants include at-most-once, at-least-once, and exactly-once delivery semantics. Trade-offs include ordering guarantees, duplicate handling, and backpressure. It is widely supported by Kafka, Pulsar, SNS, Google Pub/Sub, and Azure Service Bus Topics.
ALTERNATIVE DEFINITIONS
Wikipedia
In software architecture, publish–subscribe is a messaging pattern where senders of messages, called publishers, do not send messages directly to specific receivers, called subscribers.
Highlights decoupling of publishers and subscribers.
Enterprise Integration Patterns
A Publish-Subscribe Channel delivers a copy of a message to each subscriber.
Emphasizes channel semantics and message fan-out.
Confluent
In publish-subscribe, producers publish events to topics and consumers subscribe to those topics to receive events.
Connects the pattern directly to Kafka topics and consumers.
RELATED TERMS
Event-Driven Architecture Topic Observer Pattern Message Broker Event Bus Apache Kafka Google Pub/Sub Event Streaming Routing Key
COMPETING TERMS
Point-to-Point Messaging Queue
KNOWLEDGE AREAS
Real-time & Streaming Data Software Engineering Data Integration & Interoperability Data Architecture
TARGET AUDIENCE
Software Developer Data Engineer DevOps Engineer Cloud Architect Data Architect
EXTERNAL SOURCES
- Wikipedia - Publish–subscribe pattern
- Apache Kafka - Kafka pub-sub concepts
- Google Cloud - Google Pub/Sub overview
- AWS - AWS SNS pub/sub service
- Microsoft - Azure Service Bus topics
TOP QUESTIONS
Why use the Publish-Subscribe Pattern?
It enables decoupling, scalability, and fan-out delivery. Multiple subscribers can react to events independently. It reduces tight coupling between producers and consumers.
Category: Relevancy
What are common mistakes with Publish-Subscribe Pattern?
Ignoring message duplication and ordering leads to inconsistent consumers. Overly chatty topics cause noise. Lack of schema control breaks subscribers.
Category: Mistakes
How do you ensure reliability in Publish-Subscribe Pattern?
Use durable topics, acknowledgments, retries, and dead letter queues. Employ idempotent consumers and monitoring for lag and errors.
Category: Requirements
What competes with Publish-Subscribe Pattern?
Point-to-point queues provide one-to-one delivery. Synchronous request-response fits immediate confirmation needs.
Category: Alternatives
How does Publish-Subscribe relate to Event-Driven Architecture?
Pub-sub is a fundamental communication mechanism in EDA. Events published to topics trigger decoupled subscribers.
Category: Example
What is a hot topic around Publish-Subscribe Pattern?
Exactly-once semantics and transactional event processing are hot, especially in Kafka and Pulsar ecosystems.
Category: Topic
How do you scale the Publish-Subscribe Pattern?
Partition topics and use consumer groups for parallelism. Scale brokers and tune retention and throughput settings.
Category: Management
What’s the biggest misunderstanding about Publish-Subscribe Pattern?
Many expect strict global ordering; most systems provide per-partition ordering only. Consumers must handle reordering and duplicates.
Category: Misunderstanding
Where to start learning Publish-Subscribe Pattern?
Study Kafka or cloud pub/sub docs, build a demo with topics and consumer groups, and add schema validation.
Category: Advice