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
- 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
- "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