Skip to content
BENIBIX Learn

Publish-Subscribe (Pub/Sub)

Development🏗️ ArchitectureEvents and Messages

Also known as Pub/Sub, PubSub, Publish Subscribe, Topic

Send a message to a topic. All who listen get a copy.

Think of it like

Think of it like a radio station. It sends one show, and everyone tuned in hears it.

Example

Lucy's app publishes user signed up to a topic. The email service, the stats service and the welcome gift service each get a copy and act on it.

Why it matters

One event can start many jobs. New listeners can join without a change to the sender.

Definition

Pub/sub is a way to send messages so that every listener gets a copy. Its full name is publish-subscribe. A publisher sends a message to a named topic. Any number of subscribers listen to that topic. Each of them gets its own copy of every message. The publisher does not know who, or how many, are listening.

Common mistake

Using pub/sub when only one worker should do the job. Then each subscriber does it, and the buyer gets five emails.

Key takeaways

  1. 1
    Send to a topic. Not to a person.
  2. 2
    Everyone gets a copy. Each subscriber.
  3. 3
    Sender stays blind. Who listens is not its business.

Compare