MessagingIntermediate

Queue vs pub/sub vs log

“When would you choose a work queue, a pub/sub topic, or a Kafka-style log? What does each guarantee about who receives a message and for how long?”

What this tests

  • Delivery semantics: one consumer vs all subscribers vs replayable log
  • Knowledge of ack, visibility timeout, DLQ, retention, offsets
  • Matching the tool to fan-out, replay and ordering needs
  • Awareness of operational cost differences

Answers by level

Read the beginner answer first and notice what is missing.

A work queue delivers each message to one consumer: it is competing consumers over a shared queue, with ack, visibility timeout (redeliver if not acked in time), retry counts and a dead-letter queue for poison messages. Once acked, the message is gone. It fits background jobs — resize this image, send this email — where the point is to distribute work and never lose it.

Pub/sub delivers each message to every subscriber: OrderPlaced reaches Email, Inventory and Analytics, each with its own subscription and its own retry state. Subscribers that do not exist at publish time miss the message. It fits fan-out of facts. A log (Kafka) keeps messages for a retention period regardless of consumption; consumers track an offset per partition and can rewind. It gives fan-out and replay and per-partition ordering, at the cost of managing partitions, consumer groups, lag and rebalances.

The choice: distribute work → queue; fan-out facts to a few consumers → pub/sub; replay, ordering, high volume or many consumers reading the same stream at different speeds → log. Kafka for a job queue is a mismatch — no per-message ack, no visibility timeout, slow messages block a partition.

Green flags · Red flags

Strong green flag · Reasons from what happens to a consumed, failed, and early message under each model.
Green flags
  • Distinguishes one-consumer, all-subscribers and replayable-log semantics precisely
  • Names ack, visibility timeout, DLQ, retention, offsets, consumer groups
  • Matches each to a workload (jobs, fan-out, replay/stream)
  • Explains why Kafka is a poor job queue
  • Weighs operational cost
Red flags
  • "Kafka is a better version of a queue, so use Kafka for everything."
  • Does not know what a visibility timeout or dead-letter queue is
  • Believes pub/sub subscribers receive messages published before they subscribed
  • Uses a log for a job queue and wonders why one slow job blocks the others

Follow-up questions

F1
A poison message crashes the worker every time. What happens in each model?
F2
Analytics needs last month's events after a bug in their projection. Which model helps?
F3
When would you put a queue behind a pub/sub subscription?

Scenario

A team uses Kafka as the queue for video transcoding jobs. One 4-hour job on a partition stalls dozens of short jobs behind it, and failed jobs are retried by rewinding the offset, which reprocesses everything after them. Choose the right tool, explain the migration, and state what the DLQ and retry policy look like.

Learn this topic