Publish-Subscribe

Publish-subscribe, often shortened to pub-sub, is a messaging pattern in which senders do not address messages to specific receivers. Instead, a publisher sends a message to a named topic, and any subscriber that has registered interest in that topic receives a copy. The publisher does not know how many subscribers exist or who they are, and subscribers do not know which publisher produced a given message. This indirection is what makes the pattern loosely coupled.

The Apache Kafka introduction describes its clients in exactly these terms: “Producers are those client applications that publish (write) events to Kafka, and consumers are those that subscribe to (read and process) these events.” Topics are the channel of communication, and Kafka stresses that producers and consumers are agnostic of each other. The defining behavior that separates publish-subscribe from a plain work queue is fan-out: a single published message can be delivered to every interested subscriber, rather than to just one consumer that then removes it.

Because publishers and subscribers are decoupled, the set of subscribers can change over time without any change to the publisher. New consumers can be added to react to an existing stream of events, and old ones can be removed, all without coordination on the producing side. In log-based systems this is especially flexible, since each subscriber tracks its own position in the topic and a new subscriber can begin from the start of the retained history.

Publish-subscribe is a foundational building block of event-driven and streaming architectures. By letting many systems react independently to the same events, it supports patterns where one occurrence, such as a new order or a sensor reading, triggers updates across analytics, notification, and storage systems at once, as Jay Kreps illustrates in his Confluent writing on building event streaming platforms.