Publish/Subscribe Pattern

Learn how to implement the Publish/Subscribe pattern in Node.js applications.

Publish/Subscribe (often abbreviated to Pub/Sub) pattern is probably the best-known one-way messaging pattern. We should already be familiar with it because it’s nothing more than a distributed Observer pattern. Similar to the Observer pattern, we have a set of subscribers registering their interest in receiving a specific category of messages. On the other side, the publisher produces messages that are distributed across all the relevant subscribers. The illustration below shows the two main variants of the Pub/Sub pattern; the first is based on a peer-to-peer architecture, and the second uses a broker to mediate the communication.

Get hands-on with 1400+ tech skills courses.