What Is Publish/Subscribe?

Publish/subscribe, or pub/sub messaging is a software architecture model by which applications create and share data. Pub/sub is particularly popular in serverless and microservices architectures.

In pub/sub messaging, publishers and subscribers are independent. Publishers are not aware of subscribers, and subscribers do not know who the publishers are. Rather, publishers push data as messages to topics, and subscribers then receive the messages from the topics.

Publish/subscribe messaging software uses topics to relay data from publishers to subscribers.

Publish-Subscribe Diagram

For What Is the Publish/Subscribe Pattern Used?

Publish/subscribe patterns are common in event-driven architectures, in which publishers share events in real-time and subscribers perform some type of computation depending on the event that was published.

Pub/sub patterns also are common in microservices, where they enable developers to decouple applications by building hyper-specific services to perform one or a small handful of functions before sending the results to another microservice.

What Are the Advantages of Pub/Sub Messaging?

There are three key advantages of publish/subscribe messaging that developers commonly cite.

  • Speed. Publishers can push messages to topics in real-time. Any subscriber with interest in the topic will then receive that message in real-time, rather than periodically polling to see whether updates are available.
  • Flexibility. Publishers are not aware of subscribers. The number of subscribers can increase, shrink, or even disappear without affecting the processes of a publisher.
  • Scalability. Because everything is loosely coupled in a pub/sub messaging system, components of the system take advantage of parallelism to scale for massive data volumes or message rates.


Related Topics

Microservices   Microservices Architecture   Event-Driven Architecture

Relevant Resources

View All Resources