Why this matters: pub-sub and messaging queues look nearly identical on a whiteboard. One sentence separates them, and getting that sentence right is what makes every later design decision follow.
Key takeaway
Publish-subscribe (pub-sub) messaging is an asynchronous communication method popular in serverless and microservices architectures. It sends messages to multiple subsystems simultaneously — services subscribed to a specific topic receive any message pushed to that topic.
The shape
The canonical example: when a user posts on a social media platform, the platform delivers that post to their followers. The user is the publisher, the post is the message, and the followers are the subscribers.
The one difference from a queue
"What are the similarities and differences between a pub-sub system and queues?"
They are similar because they deliver information from producers to consumers. The difference is that only one consumer processes a message in a queue, whereas multiple consumers can process the same message in a pub-sub system.
Messaging queue
Pub-sub
Who processes a message
Exactly one consumer
Every subscriber
Adding a consumer
Splits the work — throughput goes up
Duplicates the work — each gets its own copy
Message lifetime
Typically ends when consumed
Governed by a retention policy, not by consumption
Natural fit
Task distribution — jobs that must run once
Event distribution — facts several parties need to know
Decoupling
"How are producers and consumers decoupled in a pub-sub system?"
Producers don't know who'll end up reading their information. They just send it to the system, and the consumer reads it. The system acts as a decoupling layer between producers and consumers.
Producers are not affected by slow consumers, the number of consumers, or consumer failures. We can scale them independently.
Motivation
Distributed systems often rely on vast hardware infrastructure. Pub-sub systems enhance scalability by enabling asynchronous communication. This pattern decouples producers from consumers, allowing them to operate and scale independently. Consequently, engineers can add or remove components without disrupting the wider system.
Key takeaway
A queue message is processed by exactly one consumer; a pub-sub message is read by every subscriber. Everything else follows: deletion is driven by retention rather than consumption, storage becomes a log, and adding a subscriber requires no change to the publisher.
Interview signal by level
Level
What a strong answer sounds like
L4
"Publishers send to a topic and subscribers receive the messages."
L5
States the difference precisely: "in a queue exactly one consumer processes each message; in pub-sub every subscriber gets its own copy — so adding a consumer splits work in one and duplicates it in the other."
Staff+
Draws the architectural consequence: "because the system can't know when the last subscriber has read, consumption can't drive deletion — retention does. That's why pub-sub storage is a log with per-consumer offsets rather than a queue. And the publisher's cost has to stay O(1) in subscriber count, which rules out the obvious copy-per-subscriber design."
Next: what people build with it, and what we're required to support.
Enjoying the preview?
Create a free account to unlock the rest of this course, the in-browser judge, and live AI mock interviews.