skip to content

questions

6

What is the fundamental difference between publish-subscribe (pub-sub) messaging and point-to-point queuing, in terms of how many consumers receive a given message?

level: juniorimportance: must knowfreq 85%

answer

  1. fan-out = 1-to-many, topics
  2. competing consumers = 1-to-1, shared queue
  3. adding subscriber doesn't steal messages
  4. adding worker to queue splits work
  5. same event vs same work-item

basics

~20 s

In pub-sub, every subscriber gets its own copy of each message (fan-out, one-to-many). In a queue, each message goes to exactly one consumer picked from the pool (point-to-point, one-to-one), even if many workers are listening.

solid answer

~50 s

Pub-sub is a one-to-many broadcast model: a publisher sends a message to a topic, and every subscriber currently subscribed to that topic receives an independent copy. Consumers are decoupled from each other - adding a tenth subscriber doesn't take messages away from the first nine. Point-to-point queuing is one-to-one: a message placed on a queue is delivered to exactly one consumer, even if a dozen worker processes are all polling that same queue. The queue acts as a shared work pool - the workers compete for each message, so it's often called the competing-consumers pattern. The practical consequence: pub-sub is for fan-out - notifying independent parties who each need their own view of the event - while queuing is for distributing work so each unit of work is done exactly once by exactly one worker.

go deeper

for a junior

Should state clearly that pub-sub delivers a copy to every subscriber while a queue delivers each message to only one consumer, and give one example of each.

for a middle

Should additionally explain competing consumers and be able to name concrete technologies (SQS, RabbitMQ, Kafka, SNS) that implement each model, plus note that consumer groups blur the pure distinction.

for a senior

Should reason about when to combine both patterns in one architecture (event fan-out at the service boundary, internal work queues per service) and describe the operational consequences of choosing the wrong one.

for a principal

Should assess this trade-off as a system-design lever across an org's event backbone - e.g., justifying a hybrid topic plus consumer-group architecture, or setting policy on which teams get pub-sub subscriptions vs shared work queues, given cost and coupling constraints.

## The whole question is cardinality At its core, the distinction between publish-subscribe and point-to-point queuing is about **cardinality**: how many consumers receive a copy of any single message that enters the system. ## How a message moves in each model **Mechanism, step by step.** In a point-to-point queue, a producer places a message onto a named queue — a buffer managed by a broker (RabbitMQ, Amazon SQS, ActiveMQ, etc.). 1. Any number of consumer processes can attach to that same queue, but the broker guarantees that each message is handed to exactly one of them. 2. Internally the broker typically round-robins or load-balances messages across the connected consumers, removing the message from the queue once it is acknowledged. 3. This is the **competing-consumers** pattern: workers race for messages the way employees at a shared inbox race for tickets, and the queue's job is to make sure no two employees pick up the same ticket. **Pub-sub flips this.** A producer publishes a message to a topic (or exchange/subject), and the broker (Kafka, Google Pub/Sub, RabbitMQ fanout exchange, SNS) fans that message out to every subscription currently registered on the topic. Each subscription gets its own logical copy and its own delivery cursor, so subscriber A finishing quickly doesn't affect subscriber B lagging behind. ## Two problems in similar clothing Both exist because they solve two different problems wearing similar clothing. - **Queuing** solves "I have N units of work and M workers, and I want each unit done exactly once, load-balanced across the workers, so throughput scales as I add workers." It's the messaging equivalent of a thread pool's task queue. - **Pub-sub** solves an entirely different problem: "multiple independent parts of the system need to react to the same fact, and I don't want the producer to know or care who's listening." An order-placement event might need to be seen by inventory, billing, email, and analytics — four unrelated consumers, each needing every event, none of them competing for it. ## What each one buys you The trade-offs: | | Point-to-point queuing | Pub-sub | |---|---|---| | **Gives** | natural load-balancing and back-pressure — if consumers slow down, the queue simply grows, and you can add workers to catch up, with no risk of duplicate processing across workers (though a single consumer can still get a redelivery on crash) | loose coupling and easy extensibility — a new subscriber can start consuming tomorrow without the publisher's code changing at all | | **Costs** | its cost is that it's fundamentally single-purpose: once a message is consumed, it is normally gone, so a fifth interested party cannot be added after the fact without changing the producer or duplicating messages onto another queue | that flexibility costs you: you now have N independent consumption rates to manage, N sets of unacknowledged-message backlogs, and, in most systems, no automatic load-sharing per subscriber unless you layer consumer groups on top of subscriptions | ## What goes wrong In production, the failure modes split by pattern: - **A poison message on a plain point-to-point queue.** The classic failure is a poison message with no dead-letter handling — a message a worker can never successfully process gets redelivered indefinitely, blocking or slowing throughput as workers repeatedly pick it up, fail, and requeue it. - **A slow or dead subscriber**, the recurring pub-sub failure, causing unbounded backlog growth on its own subscription while every other subscriber is fine. Because subscriptions are independent, one broken consumer doesn't stop the others, but it can silently accumulate storage cost or eventually hit a retention-window cutoff and lose messages. - **Misuse of a queue as if it were pub-sub.** Teams also frequently do this, attaching many independent consumers to one queue expecting each to see everything, and are surprised when messages are actually split between them (competing-consumers, not fan-out), silently dropping most events per consumer. ## Composing both at different layers A concrete example: a checkout service publishes an `OrderPlaced` event onto a Kafka topic (pub-sub via consumer groups) so that the inventory service, the email service, and the fraud-analytics service can each independently and durably consume the full stream at their own pace, replaying from an offset if needed. Meanwhile, inside the inventory service itself, the actual decrement-stock work items are pushed onto an internal SQS queue (point-to-point) so a pool of ten inventory workers can load-balance the work, each SKU decrement handled exactly once by exactly one worker. The two patterns are frequently composed in the same architecture at different layers: **pub-sub for cross-service event distribution, queuing for intra-service work distribution**.

  • Can a single broker support both patterns, or do you need two different technologies?
    Most modern brokers support both: Kafka does pub-sub natively via topics but achieves queue-like load-balancing within a consumer group (partitions divided among group members); RabbitMQ does queuing natively but achieves pub-sub via fanout/topic exchanges that copy a message into multiple queues. The pattern is usually a configuration/usage choice more than a product choice.
  • If you attach 5 independent consumer groups to one Kafka topic, is that pub-sub or point-to-point?
    It's pub-sub across groups (each group gets a full independent copy of the stream) combined with point-to-point within each group (partitions are load-balanced among that group's members, so within a group each message is processed once).
  • What happens if you need both fan-out to multiple services and load-balanced work distribution within each service?
    Layer them: publish to a topic for fan-out, and have each interested service either use a consumer group or drain its subscription into an internal work queue for its own worker pool - this is the checkout/inventory example above.

Pub-sub is like a radio broadcast - every tuned-in radio hears the same song independently. Point-to-point queuing is like a deli counter's ticket dispenser - each numbered ticket is served to exactly one customer, no matter how many customers are waiting.

saying these in an interview costs you the question

  • Says pub-sub and queuing are just two names for the same thing
  • Believes attaching many consumers to a plain queue gives each of them every message
  • Doesn't realize a queue message is normally removed after one successful consumption
  • Can't say who competes in competing-consumers
  • Thinks Kafka can't do point-to-point work distribution

context

open as a page

A consumer pulls a message off a queue and crashes before sending an acknowledgement back to the broker. What happens to that message, and what delivery guarantee does this behavior typically produce?

level: middleimportance: must knowfreq 75%

basics

~20 s

The broker assumes the message wasn't handled and gives it to another consumer after a timeout, so the message isn't lost. But this means the same message might get processed twice - that's called at-least-once delivery.

open as a page

In a point-to-point queue with multiple consumer instances attached, how does the broker typically decide which consumer receives which message, and what ordering guarantees (if any) survive this distribution?

level: middleimportance: must knowfreq 78%

basics

~20 s

The broker hands each message to whichever available consumer is free (round-robin or pull-based), so work spreads across consumers. Once messages are spread across multiple consumers, you generally lose the guarantee that they're processed in the exact order they were sent.

open as a page

A message repeatedly fails processing - say, due to a malformed payload a consumer can never successfully parse. Without any special handling, what happens to that message in an at-least-once queue system, and how does dead-letter queue (DLQ) routing fix it?

level: seniorimportance: must knowfreq 80%

basics

~20 s

Without a fix, the broker keeps redelivering the bad message forever, and it can jam up processing for everyone behind it. A DLQ routes a message elsewhere automatically after it fails too many times, so the queue keeps moving and someone can look at the bad message later.

open as a page

After a message has been successfully consumed, how does its fate typically differ between a traditional point-to-point queue and a pub-sub topic with multiple independent subscribers, and why does that difference matter for durability?

level: seniorimportance: should knowfreq 65%

basics

~20 s

In a queue, once one consumer finishes a message, it's normally deleted - gone for good. In pub-sub, each subscriber has its own independent copy and cursor, so one subscriber finishing doesn't remove the message for the others, and depending on the system it may still be replayable later.

open as a page

You're designing a system where an OrderPlaced event needs to independently trigger inventory update, email notification, and analytics logging at different paces, while a separate CapturePayment step must be processed exactly once by exactly one worker with strict, ordered handling per account. Would you use a pub-sub topic or a point-to-point queue for each, and how would you combine them?

level: principalimportance: should knowfreq 55%

basics

~20 s

For OrderPlaced, use pub-sub - every interested service (inventory, email, analytics) needs its own full copy at its own speed. For CapturePayment, use a point-to-point queue so only one worker handles each payment exactly once, with per-account ordering.

open as a page