# Message Queue vs Pub/Sub

URL: https://softwaredictionary.org/compare/message-queue-vs-pub-sub
Last updated: 2026-10-02

In short: In a message queue each message goes to one consumer, so workers share the load, while pub/sub copies every message to each subscriber so many services react.

## What is the difference between a message queue and pub/sub?

Both let services talk asynchronously through a broker instead of calling each other directly: a producer sends a message and moves on, and consumers handle it when they can. In a message queue, messages wait in line and each one is taken and processed by a single consumer. In publish/subscribe, a publisher sends a message to a topic, and every subscriber of that topic receives its own copy.

The difference is one receiver versus many. A queue shares work: ten workers reading one queue each take different jobs, such as resizing images or sending emails, and adding workers adds throughput. Pub/sub broadcasts facts: when an order is placed, billing, shipping and analytics can each react without the ordering service knowing they exist.

Real systems often combine the two. With RabbitMQ, Amazon SNS feeding SQS, or Google Cloud Pub/Sub, a topic can fan out to one queue per subscribing service, and that queue is then shared by the service's workers. Kafka covers both with topics and consumer groups: every group sees every message, and within a group each message goes to one member.

A common misconception is that pub/sub always keeps messages until everyone has read them. In classic pub/sub, a subscriber that is offline simply misses messages unless the system adds durable subscriptions or a queue behind each subscriber; in a queue, messages stay until a consumer confirms it has handled them.

| Aspect | Message Queue | Pub/Sub |
| --- | --- | --- |
| Who gets a message | Exactly one consumer | Every subscriber gets a copy |
| Main purpose | Share work between workers | Broadcast events to many services |
| Adding consumers | Spreads the same work over more workers | Adds another service that hears every event |
| When a consumer is offline | Messages wait in the queue | It may miss messages, unless its subscription is durable |
| Coupling | The producer knows which queue does the work | The publisher doesn't know who is listening |
| Examples | RabbitMQ queues, Amazon SQS, job queues like Sidekiq | Kafka topics, Redis Pub/Sub, Amazon SNS, Google Cloud Pub/Sub |

## Choose Message Queue when

- Each task must be done exactly once, such as sending an email or charging a card.
- You want to spread heavy work across a pool of workers.
- Messages must wait safely until a worker is free.

## Choose Pub/Sub when

- Several independent services need to react to the same event.
- You want to add new consumers without changing the producer.
- You broadcast changes, such as price updates or notifications.

## Frequently asked questions

**Is Kafka a message queue or pub/sub?**

Kafka is an event streaming platform that can act as both. Every consumer group reads every message, as in pub/sub, while the members of one group split the messages between them, as in a queue.

**Can a message queue have several consumers?**

Yes, but they compete: each message still goes to only one of them. That is how a queue spreads work across many workers.

**Which one suits microservices?**

Both are used. Queues suit commands and background jobs that must run once; pub/sub suits events that several services care about. Many systems use pub/sub topics that feed one queue per service.

---

Software Dictionary: https://softwaredictionary.org/ · https://softwaredictionary.org/llms.txt
