Web apps & software

What is publish/subscribe (pub/sub)?

Publish/subscribe, or pub/sub, is a messaging pattern in which a sender publishes a message to a named topic and every service subscribed to that topic receives its own copy, without the sender knowing who the subscribers are.

Pub/sub versus a work queue

In a work queue, each job goes to exactly one worker, which suits tasks such as resizing an uploaded photo. In pub/sub, each message is broadcast: a "new booking" message might reach the dispatch screen, the SMS notifier and the reporting service at the same time. Many brokers support both styles, so the choice is about intent, not tools.

Where you meet it

Google Cloud Pub/Sub, Amazon SNS, Azure Service Bus topics, Redis pub/sub, MQTT for IoT devices and the channels behind live dashboards and chat apps all follow this pattern. WebSocket servers often use it internally so that an update made on one server reaches users connected to another.

Details that bite

  • Delivery rules differ. Plain Redis pub/sub drops messages for subscribers that are offline; durable brokers keep them until acknowledged.
  • Duplicates happen. At-least-once delivery means subscribers must cope with seeing a message twice.
  • Topic sprawl. Without naming rules, teams end up with dozens of overlapping topics nobody owns.

Questions, answered

Yes. It is a common way to push live updates, such as vehicle positions or chat messages, to many connected users.

Most managed services let subscribers filter by attributes, so a service only receives the messages it needs.

By the Stegnor team · Updated