We use analytics cookies.We use cookies to analyze site traffic and improve your experience.
Loading...
3 system design questions lean on this idea. Each walks through the full answer.
System Design Masterclass · Messaging Event Systems
Free preview: the first 2 parts of this 9-part lesson.
Already bought the course? Sign in to read the whole lesson.
this lesson is part of
System Design Masterclass
Unlock this lesson and the 751 other paid lessons
$25 once, by PayPal
See the System Design courseread the rest of this lesson in
System Design Masterclass
Unlock this lesson and the 751 other paid lessons
$25 once, by PayPal
See the System Design coursein Messaging Event Systems
This lesson is part of the full System Design Masterclass. Unlock it along with 769 other lessons for a one-time payment.
One-time payment by card or PayPal
Get Lifetime AccessOne-time payment: UPI, card or netbanking
Get Lifetime Access18 Foundation lessons are free, no payment needed. Try them now
It is easy and good
“It is really nice and good Please join the course”
Before the internet, how did you get news? You subscribed to a newspaper. The publisher printed one edition and delivered it to thousands of subscribers. The publisher didn't care how many subscribers there were or what they did with the paper. The subscribers didn't care how the paper was printed. They just received it.
This model, one producer broadcasting to many consumers, is called Publish/Subscribe, or pub/sub. And it's the foundation of virtually every event-driven system built in the last two decades.
Here's why it matters: in a , each message goes to exactly one consumer. That's fine for task distribution. But what happens when multiple services need to react to the same event?
A user places an order on an e-commerce platform. Who needs to know?
With a simple message queue, you'd need to send the same message six times to six different queues. With pub/sub, you publish the "order placed" event once, and every interested service receives a copy. The publisher doesn't know, or care, how many subscribers exist.
This is the pattern that lets Netflix, Google, Uber, and LinkedIn scale to billions of events per day.
Pub/sub introduces a new concept between producers and consumers: the topic (also called a channel or subject).
Every subscriber gets its own copy of every message. Unlike a queue (where each message is consumed by one worker), a pub/sub topic delivers every message to every subscriber.
The critical distinction:
| Pub/Sub Topic | ||
|---|---|---|
| Delivery | One consumer per message | All subscribers get every message |
| Use case | Task distribution (do this work) | Event notification (this happened) |
| Consumer relationship | Competing consumers | Independent subscribers |
| Example | "Process this image" | "A user signed up" |
Many systems combine both: a topic fans out events to multiple subscriber groups, and within each group, a queue distributes work among competing consumers. does exactly this with consumer groups.