concept
Pub/Sub vs Point-to-Point messaging
Pub/Sub vs Point-to-Point messaging
The first question to ask before reaching for any messaging tool: should this message be handled once, or should multiple services react to it? Getting this wrong is how a single welcome email becomes 50 welcome emails per signup.
The two semantics
| Pattern | Question it answers | What happens |
|---|---|---|
| Point-to-point (work queue) | “Do this thing.” | Any consumer can grab the message, but only one does. Resize this image. Charge this card. Send this one email. |
| Pub/Sub (topic, fan-out) | “This thing happened.” | Each subscriber gets its own copy of the message and reacts independently. An order was placed → inventory updates, email is sent, analytics is recorded. |
The mistake to avoid
The canonical horror story: a team put a “send welcome email” job onto a topic. The topic correctly fanned the message out to all 50 workers. 50 workers, 50 copies, 50 emails per signup. The tool wasn’t broken — the semantics were wrong.
One question, asked once in review, prevents it:
Should this message be handled once, or should multiple services react to it?
Vocabulary is unreliable
People say “put it on the Kafka queue” or “the RabbitMQ topic” and mean different things on different days. Don’t argue about the word — ask what actually happens to a message when it arrives.
A useful mental model:
- Point-to-point = one logical inbox, multiple workers competing for messages.
- Pub/Sub = N logical inboxes, one per subscriber, each receiving a copy.
Tooling map
| Tool | Native shape | Other shape via… |
|---|---|---|
| kafka | Log (replay) — works for both; Kafka 4.0 share groups added queue semantics natively | Consumer groups for work-queue behavior |
| rabbitmq | Broker with exchanges that route to queues — both shapes via exchange types (direct, topic, fanout, headers) | n/a (both first-class) |
| sqs | Point-to-point queue, no fan-out built in | Pair with SNS for fan-out, or use EventBridge/Kinesis |
| bullmq, pgmq | Point-to-point work queues | Application-level fan-out only |
See also
- delivery-guarantees — once you’ve picked the shape, decide the guarantee
- idempotency — the universal safety net regardless of shape or guarantee
- kafka, rabbitmq, sqs — concrete tool tradeoffs