Skip to content

Message queue vs event stream

Both carry messages between systems asynchronously, and both appear under the word “messaging”. They behave very differently.

Aspect Message queue Event stream
Model Work to be done Facts that happened
After consumption Message is removed Event stays for the retention period (or forever)
Consumers Competing consumers share the work Each consumer group reads everything
Replay Not normally possible Built in: reset a consumer’s position
Ordering Often not guaranteed, or per group with special queue types Guaranteed within a partition
Scaling consumers Add consumers freely Limited by the number of partitions
Per-message features Delays, priorities, per-message retries and dead-lettering Fewer; failure handling is up to the consumer
Typical uses Background jobs, task distribution, commands to one service Event-driven integration, audit, analytics feeds, CDC, rebuilding read models
  • Each message is a task that exactly one worker should do: send this email, resize this image, process this payment.
  • You want to add workers to drain a backlog faster, with no ordering requirement.
  • You need per-message delays, priorities and dead-letter queues without building them yourself.
  • Several systems need the same events, and new consumers will appear later.
  • Order matters, for example every change to one account in sequence.
  • You need to replay history: rebuild a read model, backfill a new service, or recover from a consumer bug.
  • The events are part of your record of what happened.
  • Replay is powerful and dangerous. Replaying events into a consumer that sends emails or charges cards repeats those side effects unless the consumer is idempotent.
  • Partitions cap parallelism. A stream with 12 partitions can’t be consumed by more than 12 consumers in one group. Choosing partition keys and counts is a design decision.
  • A slow message blocks its partition. In a stream, one poison event stops everything behind it in that partition. Plan how to park it.
  • Queues aren’t faster by themselves. A queue moves waiting from the caller to the queue; it doesn’t add capacity.

Use a queue to hand out work, and a stream to publish facts. If you find yourself copying messages to several queues so different systems can see them, or wishing you could replay last Tuesday, you want a stream. If you’re building retries, delays and dead-lettering on top of a stream for a job system, you want a queue.

Written and edited by Abhinav Taduka, enterprise software architect.