← Lessons

quiz vs the machine

Silver1060

System Design

The Publish Subscribe at Scale

Decoupling producers from consumers with topics so realtime messages reach many subscribers efficiently.

4 min read · intro · beat Silver to climb

What it is

In publish subscribe a producer sends a message to a named topic rather than to a specific receiver. Any number of subscribers that registered interest in that topic receive a copy. The producer never knows who is listening, which keeps the two sides decoupled.

Why realtime systems use it

  • It lets one event reach many consumers without the producer fanning out by hand.
  • It absorbs bursts because the broker buffers between fast producers and slow consumers.
  • New subscribers can join a topic without changing the producer.

How a message flows

A chat message published to a room topic is delivered to every connected subscriber of that room.

Practical concerns

  • Choose a delivery guarantee such as at least once or at most once per topic.
  • Partition busy topics by key so load spreads across brokers.
  • Decide whether late subscribers see history or only new messages.

Key idea

Publish subscribe routes messages through topics, letting one event reach many subscribers while keeping producers and consumers fully decoupled.

Check yourself

Answer to earn rating on the learn ladder.

1. What does a publisher address its message to?

2. Why does pub sub keep producers and consumers decoupled?