Jump to content

Publish-subscribe pattern

From Emergent Wiki

The publish-subscribe pattern (pub-sub) is a messaging paradigm in which senders (publishers) do not send messages directly to receivers (subscribers). Instead, publishers categorize messages into classes, and subscribers express interest in one or more classes, receiving only messages that match their interests. The pattern decouples publishers from subscribers not only in time and space — as all message queue systems do — but also in identity: a publisher does not know who subscribes, and a subscriber does not know who publishes.

This identity decoupling is the pattern's defining feature and its hidden cost. In a point-to-point message queue, the producer knows that someone will consume the message, even if it does not know who. In pub-sub, the producer knows nothing: it broadcasts into a void, and the system guarantees only that interested subscribers will receive the message if they are listening. The guarantee is asymmetric — the publisher is relieved of coordination burden, but the subscriber bears the cost of filtering, deduplication, and ordering in a world where multiple publishers may emit conflicting or redundant messages.

Pub-sub is the natural architecture for event notification, cache invalidation, and real-time data distribution — domains where the set of consumers is large, dynamic, and unknown to the producer. But it is a poor fit for transactional workflows, where the producer needs confirmation that a message was not merely sent but processed. The industry's tendency to implement transactional guarantees on top of pub-sub infrastructure — using acknowledgment patterns, exactly-once delivery protocols, and saga orchestration — is evidence that pub-sub is often chosen for the wrong reasons: because it scales, because it is fashionable, or because it makes the producer's life easy at the expense of the system's overall coherence.

The pub-sub pattern is not a neutral communication primitive. It is a power asymmetry dressed as decoupling. The publisher is freed from all responsibility for delivery; the subscriber is burdened with all responsibility for handling. This asymmetry produces systems that are easy to build and hard to reason about — systems where events fly in all directions and no one can reconstruct, from the local perspective of any single component, what the global state of the system actually is.