Skip to main content
Dilectus
System Design · Messaging & streaming

Message Queue vs Pub/Sub vs Event Stream: How to Choose

Learn the differences between message queues, pub/sub, and event streams, with diagrams, trade-offs, and interview-friendly guidance.

AI-generated explainer by Dilectus · · 8 min read

When systems grow, services need to talk without blocking each other. Queues, pub/sub, and event streams all help decouple producers from consumers, but they solve slightly different problems: one-to-one work dispatch, one-to-many fanout, and durable ordered event history.

Choosing the wrong one can create hidden bottlenecks, duplicate processing, or data loss. The trick is to match the communication pattern to the business need: do you want a task to be handled once, a message to reach many subscribers, or a stream of facts that can be replayed later?

The three patterns at a glance

Think of them as three different ways to move information:

Producer ---> [ Queue ] ---> Worker A
                 |-------> Worker B

Producer ---> [ Pub/Sub Broker ] ---> Subscriber A
                               |--> Subscriber B
                               |--> Subscriber C

Producer ---> [ Event Stream Log ] ---> Consumer Group A
                                 |---> Consumer Group B
                                 |---> Replay from offset

Quick mental model

  • Message queue: “Do this task once.”
  • Pub/sub: “Tell everyone who cares.”
  • Event stream: “Record what happened, then let consumers read at their own pace.”

A lot of systems use a mix. For example, an order service may publish an OrderPlaced event to a stream, while a background worker queue handles image resizing for the same order.

Message queues: work distribution with one consumer per message

A message queue is usually used for jobs. A producer sends a message, and one consumer takes responsibility for it. If you have 10 workers, the queue can spread messages across them so each job is processed once.

Typical flow

  1. Producer enqueues a job, such as resize image 123.
  2. Broker stores the job until a worker is available.
  3. One worker claims the job.
  4. Worker processes it and acknowledges success.
  5. If the worker crashes before ack, the message is retried.

Why teams use it

  • Smooths traffic spikes: a burst of 10,000 jobs does not overwhelm the backend immediately.
  • Improves latency for the user-facing request: the API can return quickly after enqueueing.
  • Supports retries for transient failures.

Trade-offs

A queue is great when only one consumer should do the work. But if multiple services need the same information, a queue alone is the wrong abstraction unless you duplicate the message into multiple queues.

It also introduces operational concerns:

  • At-least-once delivery is common, so consumers must be idempotent.
  • Ordering may be limited to a partition, a queue, or a FIFO mode depending on the system.
  • Backlogs can build up if consumers are slower than producers.

Pub/sub: broadcast to many interested subscribers

Pub/sub stands for publish/subscribe. A producer publishes a message to a topic, and every subscriber to that topic receives a copy. This is useful when multiple services need the same fact independently.

Typical flow

  1. Producer publishes PaymentSucceeded to a topic.
  2. Broker routes the event to all subscribers.
  3. Billing service updates invoices.
  4. Email service sends a receipt.
  5. Analytics service records the event.

Where it fits well

  • Notifications sent to multiple downstream systems.
  • Microservices that react to shared business events.
  • Loose coupling between teams: publishers do not need to know who consumes the event.

What to watch out for

Pub/sub is often misunderstood as “fire and forget.” In practice, delivery guarantees vary by broker and configuration. Some systems keep messages only briefly, some support durable subscriptions, and some require consumers to track their own offsets or checkpoints.

Also, pub/sub is about distribution, not history. If a subscriber is offline and the system does not retain messages for it, that subscriber may miss events.

Event streams: durable ordered logs you can replay

An event stream is more than a broadcast mechanism. It is a persistent append-only log of events, usually ordered within a partition or shard. Consumers read from the stream at their own pace and remember where they left off.

Typical flow

  1. Producer appends OrderPlaced to a stream.
  2. The event is stored durably with an offset or sequence number.
  3. Consumer group A reads new events and updates the order view.
  4. Consumer group B reads the same stream for fraud checks.
  5. Later, a new consumer can replay old events from the beginning.

Why streams are powerful

  • Replay: rebuild a projection, recover from bugs, or backfill a new service.
  • Multiple independent consumers: each keeps its own offset.
  • High throughput: append-only logs are efficient for large volumes.
  • Event sourcing friendly: the stream becomes the system of record for changes.

Trade-offs

Streams give you flexibility, but they also increase complexity:

  • You must manage offsets, retention, and consumer lag.
  • Downstream consumers need to handle duplicates and out-of-order events where applicable.
  • Replaying old events is useful, but schema changes can make old data harder to interpret.

Queue vs pub/sub vs event stream

AspectMessage queuePub/subEvent stream
Main goalDistribute workFan out messagesStore and replay events
Message deliveryUsually one consumer gets a messageAll subscribers get a copyConsumers read from a durable log
Best forBackground jobs, task processingNotifications, service fanoutAnalytics, event-driven systems, reprocessing
Replay supportLimited or queue-specificOften limitedStrong, by design
Consumer stateUsually queue ack onlySubscriber-specificOffset/position per consumer
OrderingOften limited or partition-basedTopic/partition dependentUsually ordered within a partition
Typical failure modeBacklog, retries, duplicate workMissed messages if not durableConsumer lag, retention issues

A useful shortcut:

  • If the message is a job, think queue.
  • If the message is a signal for many services, think pub/sub.
  • If the message is a fact you may want to replay, think event stream.

How to choose in a real system

Start with the business question, not the technology name.

1. Does exactly one worker need to do the job?

Use a queue. Example: generate a PDF, send one email, transcode one video.

2. Do several services need the same notification?

Use pub/sub. Example: order created, user signed up, payment captured.

3. Do you need durable history and replay?

Use an event stream. Example: rebuild search indexes, recompute user timelines, feed analytics, recover from a bad deploy.

4. Do you need both fanout and replay?

Use an event stream and let multiple consumers read it. This is common in larger systems because it combines distribution with retention.

5. Do you only need async decoupling, not long-term history?

A queue may be simpler and cheaper to operate.

Common failure modes and trade-offs

ProblemQueuePub/subEvent stream
Duplicate processingCommon; use idempotencyCommon; subscribers may see duplicatesCommon; consumers may re-read after restart
Lost messagesIf ack/retry is misconfiguredIf subscriber is offline and no durabilityIf retention is too short or offsets are mishandled
Hot partitionsPossiblePossibleCommon if one key gets too much traffic
Consumer slowdownQueue depth growsSubscriber falls behindConsumer lag grows
Schema evolution painModerateModerateOften higher because of replay

A practical rule: design consumers as if they may receive the same message more than once. That is safer than assuming perfect exactly-once behavior, which is hard to guarantee across real distributed systems.

When to use it (and when not to)

Use a message queue when

  • A task should be handled once by one worker.
  • You want to absorb spikes and retry failures.
  • The result matters more than the full event history.

Do not use a queue when

  • Multiple downstream services need the same event.
  • You need to replay old data for new consumers.
  • You are trying to build a durable audit trail.

Use pub/sub when

  • Many services must react to the same event.
  • You want low coupling between publishers and subscribers.
  • Missing a message is acceptable only if the broker and subscription model make that safe.

Do not use pub/sub when

  • You need strong replay semantics by default.
  • Only one consumer should process the work.
  • You need the broker to act as a long-term event store.

Use an event stream when

  • You need ordered, durable events with replay.
  • You may add new consumers later.
  • You want to reconstruct state from the event history.

Do not use an event stream when

  • The use case is a simple background job queue.
  • Your team is not ready to manage offsets, retention, and consumer lag.
  • The extra operational complexity does not buy you anything.

How this comes up in interviews

Interviewers usually probe whether you can map requirements to the right abstraction, not whether you can list product names.

What they may ask

  • How would you decouple a web API from slow downstream work?
  • How would multiple services react to the same business event?
  • How would you reprocess events after a bug fix?
  • How would you avoid duplicates and handle retries?

A strong answer structure

  1. Clarify the requirement: one consumer or many, replay or not, ordering needs, throughput, failure tolerance.
  2. Pick the pattern and explain why.
  3. Mention delivery semantics and idempotency.
  4. Add operational concerns: backlog, consumer lag, retention, dead-letter handling.
  5. Call out what you would monitor.

What good answers sound like

  • “If only one worker should process each job, I’d use a queue.”
  • “If billing, email, and analytics all need the same event, I’d publish to a topic.”
  • “If we need to rebuild projections later, I’d use an event stream with consumer offsets and retention.”

A nice follow-up is to mention that real systems often combine them. For example, an order service can emit an event stream for business history and also enqueue a separate job for image processing.

Key takeaways

  • A queue is for one task being handled by one consumer.
  • Pub/sub is for broadcasting the same message to multiple subscribers.
  • An event stream is a durable log that supports replay and independent consumers.
  • Delivery is often at-least-once, so consumers should be idempotent.
  • The right choice depends on who needs the message, for how long, and whether replay matters.
  • In interviews, explain the requirements first, then choose the pattern and discuss trade-offs.

Frequently asked questions

Is pub/sub the same as an event stream?
Not exactly. Pub/sub focuses on distributing messages to subscribers, while an event stream keeps a durable ordered log that consumers can read and replay later. Some modern systems support both patterns, but the design goals are different.
Can a message queue be used for pub/sub?
Sometimes, but usually only by duplicating messages into multiple queues or using broker features that behave more like topics. That works for small cases, but it is usually less natural than using a real pub/sub model.
Why do distributed messaging systems often deliver messages more than once?
Because retries, crashes, and network failures are normal in distributed systems. At-least-once delivery is easier to provide than perfect exactly-once processing, so consumers should be built to handle duplicates safely.
When should I choose an event stream over a queue?
Choose an event stream when the event itself is important as durable history, or when you may need to replay it for new consumers, backfills, or recovery. Choose a queue when you mainly need background task execution with one worker handling each job.