System Design · Architecture under constraints

How does publish-subscribe differ from a message queue?

Mediumpub-subfan-outconsumer groupsUpdated Oct 2026
Quiz this track

Short answer

A queue delivers each message to one competing consumer; pub-sub delivers each message to every subscribed consumer or group. Pub-sub is for fan-out, queues are for work sharing.

In a queue, consumers compete: each message is processed by one worker. In publish-subscribe, a publisher sends to a topic and every subscription receives a copy. That makes pub-sub suitable for notifying independent services, while a queue suits distributing tasks.

The building blocks

  • Topic: a named stream of messages, often partitioned for scale
  • Subscription: an independent consumer view, with its own position or offset
  • Consumer group: a set of workers that share the partitions of a subscription
  • Filtering: subscribers receive only messages matching an attribute or key
  • Retention and replay: some systems keep messages so a new consumer can read history

Fan-out changes the failure model. If one subscriber is slow, it should not block the others, so subscriptions need independent queues or offsets and independent retry policies. If a subscriber is down, the system must decide whether to retain messages, drop them or buffer them for a bounded time. That decision is a product requirement, not a broker default.

Ordering usually applies per partition key. If all events for one account must be processed in order, route by account id and let a single consumer own that partition. Global ordering across a topic is expensive and rarely necessary. Consumer groups scale by adding partitions, not by adding workers beyond the partition count.

Pub-sub makes delivery look easy but moves complexity into subscribers. Each one needs idempotency, its own dead-letter handling and a plan for schema changes. A new subscriber can also create a large replay load on the broker.

Follow-ups you should expect

Interviewers use these to check whether the first answer was understanding or memorisation.

  1. 1How do you preserve ordering for one user across partitions?
  2. 2What happens to messages when a subscriber is offline?
  3. 3How does a consumer group differ from a subscription?
  4. 4How do you introduce a new subscriber without reprocessing everything?

Say it in the interview

A queue is for work sharing, where one consumer handles each message, while pub-sub is for fan-out, where every subscription gets a copy. I give each subscriber its own offset and retry policy so one slow consumer does not block the rest. Ordering is per partition key, so I route by the entity that needs order. Each subscriber still has to be idempotent and handle schema evolution on its own.

Use this as a model, not a script. Saying it in your own words is what makes it survive follow-up pressure.

Related questions

Reading is step one

Now say it out loud.

Understanding an answer and delivering it under pressure are different skills. Rehearse this topic in a live System Design mock interview and get scored feedback on depth, clarity and confidence.