← Lessons

quiz vs the machine

Silver1100

System Design

The Publish Subscribe Pattern

One message fans out to every interested subscriber.

4 min read · intro · beat Silver to climb

What it is

In publish subscribe, a publisher sends a message to a topic and every subscriber registered on that topic receives a copy. The publisher does not know who the subscribers are.

How it works

  • A publisher writes a message to a named topic.
  • The messaging system delivers a separate copy to each active subscriber.
  • Subscribers come and go without the publisher changing.

Why it matters

  • Gives loose coupling: senders and receivers never reference each other directly.
  • Supports broadcast and event driven designs where many services react to one event.
  • Makes the system extensible: add a subscriber without touching producers.

The tradeoff is reduced control. The publisher cannot guarantee a subscriber acted, and subscribers added after a message was sent may miss it unless the system retains history.

Key idea

Publish subscribe delivers one published message to all subscribers of a topic, decoupling producers from an unknown set of consumers.

Check yourself

Answer to earn rating on the learn ladder.

1. How many copies of a published message do subscribers receive?

2. What does the publisher know about its subscribers?