1. What Is It?

A queue is a delivery channel where each message is consumed by exactly one worker — multiple workers compete for messages and share the load. A (publish/subscribe) channel is one where each message is delivered to every subscriber — multiple consumers each get their own copy. 's " groups" express both patterns within the same system: workers in the same group share the load (queue behavior), workers in different groups each see every message ( behavior).

The problem they solve: how to move work or facts between processes asynchronously. Without queues, you can't horizontally scale a worker pool against a backlog. Without pub/sub, you can't fan out the same event to many independent consumers without the knowing each one.

Kafka combines load sharing and fan-out

Thumbnailer instances share the uploads partitions, while the analytics group reads every event independently; two of the twenty thumbnailer instances are shown.

Kafka's uploads topic feeds thumbnailer and analytics groups, with two of thumbnailer's twenty instances shown.

Text version
  1. Kafka's uploads topic feeds thumbnailer and analytics groups, with two of thumbnailer's twenty instances shown.
  2. An event in one partition reaches one thumbnailer instance and the analytics group.
  3. An event in another partition reaches the other thumbnailer instance and the same analytics group.
  4. Within thumbnailer, instances share partitions; across groups, both groups read every event.
Quick check

Your e-commerce platform publishes an 'order_placed' event whenever a customer checks out. Both the inventory service and the email notification service need to react to every order — independently of each other. Which messaging pattern should you use to deliver these events?

Choose one answer

2. How It Works

Queue (work distribution):

  1. writes a message to the queue.
  2. The delivers the message to one of N competing workers.
  3. The worker acks; the deletes (or hides) the message.
  4. If the worker fails before acking, the message becomes visible again and another worker picks it up.

(broadcast):

  1. publishes a message to a .
  2. The broker delivers a copy to every subscriber.
  3. Each subscriber tracks its own progress independently.
  4. A new subscriber may (or may not) see historical messages, depending on the broker.

unifies both via groups. Partitions in a are distributed across the consumers of a single group (queue semantics within the group). Multiple groups each independently consume every ( across groups).

Concrete example. An image-upload event needs two things to happen: generate a thumbnail (one worker is enough), and update analytics (separate system).

  • Queue: A thumbnail-jobs SQS queue with 20 worker processes. Each upload produces one job; one worker handles it.
  • Pub/sub: An uploads SNS topic. The thumbnail service subscribes; the analytics service subscribes. Each gets every event.
  • unified: Topic uploads with thumbnailer (20 instances sharing partitions) and analytics (separately reading every event).

One upload reaches both services

The uploads topic delivers each image-upload event to both the thumbnail service and the analytics service.

The producer publishes an image-upload event to the uploads topic.

Text version
  1. The producer publishes an image-upload event to the uploads topic.
  2. The topic sends a copy to both services because each needs the same event.
  3. Each service processes its own copy, so one can finish while the other is still processing.
Quick check

Your team needs to process uploaded videos: a transcoding service with 10 worker instances should handle each video exactly once, while a separate notification service and a separate analytics service each need to receive every upload event independently. Which messaging setup best satisfies all three requirements?

Choose one answer

3. What Mid-Senior SWEs Actually Need to Know

  • Queue semantics need ack/nack and visibility timeouts. SQS, RabbitMQ: a message is "in flight" while a worker holds it; if not acked within the timeout, it reappears. Setting the timeout too low causes duplicates; too high causes stuck messages on crashed workers.
  • without persistence loses messages. Redis delivers only to subscribers connected at publish time. SNS drops a message once its delivery retries run out (unless a dead-letter queue is attached). A that was down too long misses events forever. Modern pub/sub (, Pulsar, Kinesis) persists for a retention window precisely to fix this.
  • "Fan-out from a queue" is a common antipattern. Don't have one queue with N workers each filtering "is this for me?" — use pub/sub (or a per ) instead.
  • consumer-group counts matter. Workers within a group are limited by count: 12 partitions = at most 12 active workers in a group; adding a 13th means one sits idle.
  • Ordering rules differ.
    • Queues like SQS standard: no ordering. FIFO SQS: per MessageGroupId.
    • Kafka: per- ordering. Partition by your ordering key.
    • Pub/sub topics: typically no global ordering across subscribers.
  • Common misunderstanding: SNS-style pub/sub is sometimes thought of as "real-time" or "low latency" — it is, but it has no replay. If you need both fan-out and replayability (analytics, debugging, new consumer onboarding), you need a log-based pub/sub like Kafka.

A timeout makes undeleted messages visible again

An SQS message becomes visible again if it is not deleted before the visibility timeout expires.

A visible SQS message is available for a worker to pick up.

Text version
  1. A visible SQS message is available for a worker to pick up.
  2. The broker delivers it to one worker, and the message becomes in flight.
  3. If the worker crashes before deleting the message, the visibility timeout makes it available again.
  4. Another worker picks up the undeleted message, so processing can repeat.
  5. After processing, the worker calls DeleteMessage to remove the message from the queue.

4. Tradeoffs & Decisions

If you need...Pick...Choose the other when...
Distribute work across a worker pool, each job done onceQueue (SQS, RabbitMQ)Multiple independent systems each need the same input
Fan-out events to many independent servicesPub/sub (Kafka, SNS, EventBridge)Only one consumer ever, and it's pure work-queue semantics
Replay history, add new consumers laterLog-based (Kafka, Pulsar, Kinesis)Storage cost matters and old data is worthless
Per-message ack with redelivery on failureQueue with visibility timeoutYou can re-process from offsets (log-based)
Both fan-out and load-sharing within each consumerKafka with consumer groupsYou don't need replay — SNS → SQS fan-out is simpler

Key tradeoff: delete-on-consume vs append-only log. Classic queues delete messages once consumed — cheap, simple, but no replay. Log-based brokers retain messages for a window — heavier storage, but they let you onboard a new that re-reads from the beginning, debug by inspecting history, and reprocess after a bug.

Replay changes the storage decision

Classic queues delete acknowledged messages, while log-based brokers retain history for replay.

Classic queues delete acknowledged messages, while log-based brokers retain them for a window.

Text version
  1. Classic queues delete acknowledged messages, while log-based brokers retain them for a window.
  2. Retained history lets a new consumer read earlier events or reprocess them after a bug.
  3. Keeping that history costs more storage, so decide whether old events are worth replaying.
Quick check

Your team discovers a bug that caused an order-processing service to silently miscalculate totals for the past 6 hours. You need to reprocess all affected messages through a corrected version of the service. Which messaging system characteristic makes this possible, and which type of broker provides it?

Choose one answer

5. Interview & System Design Cheat Sheet

  • A queue distributes one message to one worker — used for work. A delivers one message to every subscriber — used for facts.
  • collapses both into one mental model: partitions + groups. Within a group = queue. Across groups = .
  • Always ask: "Will another team need this data later?" If yes, use a log-based now — retrofitting fan-out onto a queue is painful.
  • Ordering requires -key control () or MessageGroupId (SQS FIFO). Anything else is best-effort.
  • The replay capability of log-based systems is the single biggest reason Kafka displaced traditional message queues in event-driven backends.

Common follow-ups:

  • "Why not just use SNS → SQS fan-out?" — Works well for low-throughput notification fan-out without replay needs. Fails when you want a new analytics to backfill the last week of events.
  • "How does Kafka act as a queue?" — One with N consumers shares the 's partitions. That's a queue. The "queue" persists, and unlike SQS, workers are capped at the count and progress is a committed per partition, not a per-message ack.
  • "What guarantees does pub/sub give about ordering?" — Generally none across subscribers. Within a single partition / message-group, ordering is preserved per consumer.

If asked to design X, anchor on this: Decide for each interaction whether the consumer side is "work to distribute" (queue) or "facts to broadcast" (pub/sub). Then ask whether replay matters. Those two answers pick the .

Quick check

Your team uses an SQS queue to publish order-placement events. A new analytics team now wants to consume those same events and backfill the last week of data to bootstrap their pipeline. What is the core problem with the current setup, and what should you have used instead?

Choose one answer

Reading

On this page

My notes

Sign in to keep highlights and notes.

Glossary history

Click dotted jargon to save explanations here.