All the basics

What is publish and subscribe?

Announce news once to a shared board, and every service that signed up for that kind of news hears it.

Think of a radio tower. The station broadcasts once, and everyone tuned to that channel hears it, whether the station knows them or not.

Press Play to watch it run · 5 steps

Without a topic, Orders phones each service itself. With a topic, it announces once and the listeners hear it.

One announcement, many listenersWithout a topic, Orders phones each service itself. With a topic, it announces once and the listeners hear it.OrdersTopicEmailAnalyticsRewards

Tap any box to see what it is and what it talks to.

  • Service
  • Pub/Sub
Open in playground
Text description
  1. A customer orders. The Orders service phones Email itself.
  2. Email answers. One call done.
  3. Now Orders phones Rewards too.
  4. Rewards is down, and Orders is stuck waiting.
  5. Each new service means changing Orders to call one more.
  • The sender announces once and does not know who listens.
  • Adding a listener never means changing the sender.
  • Loose coupling is the gain, and hidden dependencies are the price.

Reach for it when

When one event, like order placed, feeds email, rewards and analytics, and more listeners will come later. One receiver? Call it directly.

The catch

Orders cannot see who listens, so renaming one field in the message can quietly break Analytics, which nobody remembered.

Say it in an interview“I would publish an event to a topic so new consumers can subscribe without touching the producer. I would version messages, since I cannot see every subscriber.”