Skip to content

Search

Articles, tools, solutions and knowledge base guides

Start typing to search across articles, tools and apps.

Event-driven architecture: queue, event bus or stream

Event-driven architecture is not primarily a broker-selection problem. First define the semantics the system needs: whether one job should be handled by one worker, whether one event should reach many independent consumers, or whether event history must remain durable and replayable. Queues, pub/sub event buses and streams solve different problems, even though modern products often support more than one of these models.

Published Written by Reading time 22 min read
On this page Contents: quick navigation between sections

What event-driven architecture actually means

Event-driven architecture decouples event producers from consumers through an intermediary channel such as a broker. A producer publishes an event without directly invoking a specific consumer. [1]

This reduces temporal and addressing coupling, but shifts complexity into delivery semantics, duplicates, ordering, retries, observability and contract evolution.

Not every asynchronous interaction has the same semantics. Work queues, pub/sub and durable streams should be evaluated separately. [2][4][9]

Command, message and event are not the same thing

A message is a general data envelope exchanged between components. An event reports that something happened, while a command normally expresses an intent for a particular action to be performed.

Microsoft describes an event as notification of a change or action, while message is the broader packet of data being communicated. [2]

That distinction affects topology: a command normally has an expected handler, while an event can have zero, one or many independent consumers.

Queue, event bus and stream differ in semantics

ModelWho receives itHistory and replayBest fit
QueueOne of the competing workersUsually not the primary goalWork distribution and load leveling
Pub/Sub Event BusEvery independent subscriptionDepends on brokerNotify many systems
Durable StreamConsumers track their own positionsYes, according to retentionReplay, history, streaming and projections

With competing consumers, several workers read from one channel but each individual message is handled by one of them. [4]

With pub/sub, every independent subscription can receive its own copy of an event. [2]

With a durable stream, events remain in the log according to retention policy and consumers track their own positions and can replay older data. Kafka and NATS JetStream support this model. [9][13]

Queue: one job, one of many workers

A queue is a natural choice when a job should be performed once by one available worker. The Competing Consumers pattern lets worker count scale independently from producers. [4]

Queue-Based Load Leveling uses the queue as a buffer between a fast producer and slower processing capacity, absorbing temporary bursts. [3]

Retries, poison messages and dead-letter handling must still be designed. Microsoft also notes that many queue services use at-least-once delivery, so consumers should be idempotent. [3]

Event bus and pub/sub: one event, many independent consumers

The Publisher-Subscriber pattern lets a producer publish without knowing the receiver list. A broker or event bus distributes the event to separate subscriptions. [2]

This fits cases where billing, fulfillment, analytics and notifications all react independently to the same OrderPaid event.

Pub/sub does not automatically imply durable history or replay. Those properties depend on the broker and subscription model.

Stream: durable history and independent consumer positions

Kafka topics retain events according to configured retention. An event is not removed just because a consumer read it. [9]

A Kafka consumer tracks offsets and can seek backward to reprocess earlier records. [10]

NATS JetStream also adds persistence, replay and stateful consumers that can start at the beginning, latest message, a sequence or a point in time. [13]

RabbitMQ, Kafka and NATS are not simple substitutes

ProductCore modelStrengthMain caveat
RabbitMQExchanges, queues and optional streamsRouting, work queues, pub/sub, ack/confirmSemantics depend on queue/stream type and configuration
Apache KafkaPartitioned durable logRetention, replay, consumer groups, high throughputOrdering is per partition and exactly-once has a defined scope
NATS Core + JetStreamLightweight pub/sub, queue groups, JetStream for persistenceSimple messaging, low latency, optional durabilityCore NATS is at-most-once; replay requires JetStream

RabbitMQ supports exchanges, queues and streams. Kafka centers on a partitioned durable event log. Core NATS focuses on lightweight pub/sub and request/reply, while JetStream adds persistence and replay. [5][6][9][12][13]

Their capabilities overlap: RabbitMQ has streams, Kafka consumer groups can resemble competing consumers, and NATS has queue groups.

The better selection criterion is required behavior: consume work once, fan an event out to independent subscribers, or retain an event history for replay.

RabbitMQ: exchanges, queues, acknowledgements and confirms

In AMQP 0-9-1, producers publish to an exchange. The exchange routes messages to queues, streams or other exchanges according to its type and bindings. RabbitMQ supports direct, topic and fanout exchanges among others. [5]

Fanout sends a copy to every bound destination, direct matches an exact routing key, and topic uses patterns. [5]

Consumer acknowledgements and publisher confirms solve different problems. Consumer acknowledgements cover delivery and processing lifecycle, while publisher confirms tell a producer the broker accepted the publication. [7]

Kafka: partitions, consumer groups, retention and replay

A Kafka topic is divided into partitions. Events with the same key are routed to the same partition, and Kafka guarantees order for records read from a particular topic-partition. [9]

Inside a consumer group, each partition is assigned to one consumer at a time. A different consumer group can independently read the same topic. [10][11]

Because events remain in the topic according to retention, Kafka supports replay, projection rebuilding and multiple independent consumers of historical data. [9][10]

Core NATS and JetStream have different semantics

Core NATS pub/sub delivers a copy to every active subscriber, while a queue group selects one group member for each message. [12]

Core NATS provides at-most-once delivery and does not retain messages for offline subscribers. When work must survive a worker failure or be replayed, NATS documentation points to JetStream. [12][13]

JetStream stores messages in streams and provides stateful consumers with acknowledgements and redelivery. [13]

At-most-once, at-least-once and exactly-once

At-most-once can lose a message but should not redeliver it. At-least-once prioritizes avoiding loss at the cost of possible duplicates.

Kafka also documents exactly-once processing for certain Kafka-to-Kafka flows using idempotent producers, transactions and suitable consumer isolation. [10]

That statement should not be generalized to every external system. Kafka notes that exactly-once for external destinations requires cooperation or coordination with that destination. [10]

Idempotency therefore remains a practical requirement in most integrations.

Ordering is usually local, not global

Kafka guarantees ordering within one partition, not globally across every partition of a topic. [9]

In RabbitMQ, strict ordering with multiple consumers can be affected by parallel processing and redelivery. RabbitMQ documents Single Active Consumer or a single consumer per queue as options when strict ordering matters. [6]

If order matters to the business, define its scope, such as per order, customer or aggregate, and choose the partition key or topology accordingly.

Retry, dead-lettering and idempotency

Retry without idempotency can apply a business effect more than once. This is especially important with at-least-once delivery, where redelivery is expected behavior. [3][13]

After retry is exhausted, a dead-letter queue or diagnostic channel can isolate unprocessable messages instead of retrying forever. [3]

RabbitMQ quorum queues can provide at-least-once dead-lettering with publisher confirms, but the default dead-letter behavior has different guarantees and requires deliberate configuration. [8]

An idempotency key, deduplication record or upsert is often more practical than trying to achieve perfect end-to-end exactly-once.

Transactional Outbox solves the dual-write problem

A classic failure occurs when an application commits a database update and then publishes an event. A crash between the two can leave the database changed without the corresponding event.

Transactional Outbox writes the business change and an outbox event record in the same local database transaction. A separate relay later publishes that record to the broker. [14]

AWS notes that the relay can publish more than once, so the consuming service should still be idempotent. [14]

CloudEvents can standardize event metadata such as id, source, specversion and type, but it is not a broker or delivery mechanism. [15]

How to choose the right model

NeedNatural modelWhy
One task should be handled by one workerQueueCompeting consumers distribute work
Many systems react to one eventPub/Sub Event BusEach subscription receives its own copy
History and reprocessingDurable StreamRetention and consumer position enable replay
Different needs in one domainCombinationQueues and streams can serve different stages of one process

If one task should be performed by one worker, start with a queue. If many independent systems must react to the same event, choose pub/sub. If you need durable history, replay, independent consumer positions or stream processing, use a stream. [2][4][9][13]

In a complex system, these models can coexist. A stream event may feed projections and analytics while a separate work queue distributes expensive jobs to workers.

Choose a product only after writing down requirements for retention, delivery semantics, ordering, throughput, backpressure, retry, disaster recovery and operational complexity.

  • Classify each contract as a command, event or general integration message.
  • Decide whether one consumer or many independent subscribers should receive each message.
  • Decide whether history must be retained and replayable.
  • Define the required scope of ordering instead of simply requesting 'ordering'.
  • Assume duplicates are possible with at-least-once and design idempotent consumers.
  • Separate retries for transient failures from poison-message handling and DLQ.
  • If an event follows a database change, consider Transactional Outbox.
  • Do not choose RabbitMQ, Kafka or NATS based on product popularity alone.

Choose the communication model before choosing the technology. A queue is natural for work that one of many workers should perform, pub/sub for events that many independent systems should react to, and a stream for history, replay and independent consumer positions. Large systems often combine these models. The critical design work is making delivery semantics, ordering, retries, dead-lettering, idempotency and event publication alongside data changes explicit.

Event-Driven Architecture Message Queue Event Bus Event Streaming RabbitMQ Apache Kafka NATS Pub/Sub Transactional Outbox Distributed Systems

Frequently asked questions

Does event-driven architecture require Kafka?

No. EDA is an architectural style, not a product. The channel can be a queue, pub/sub broker or stream. [1]

What is the main difference between queue and pub/sub?

With competing consumers, one message is handled by one consumer from the group. With pub/sub, every independent subscriber can receive its own copy. [2][4]

How is a stream different from a queue?

A stream retains history according to retention and consumers track their own positions and can replay data. A classic queue primarily hands work to a consumer. [9][10][13]

Does RabbitMQ support pub/sub?

Yes. A fanout exchange routes a copy to every bound queue, stream or exchange. Topic and direct exchanges use different routing rules. [5]

Does Kafka guarantee global ordering?

No. Kafka guarantees ordering within a specific topic-partition. [9]

Is a Kafka consumer group similar to a worker queue?

In one sense: each partition is assigned to one consumer in the group. Other groups can independently read the same topic. [10][11]

Does Core NATS retain messages for offline subscribers?

No. Core NATS is at-most-once. Persistence, acknowledgements, redelivery and replay come from JetStream. [12][13]

Does at-least-once mean duplicates are possible?

Yes. Redelivery is part of the model, so consumers should be idempotent. [3][13]

Does exactly-once solve every duplicate problem?

No. Kafka offers exactly-once for defined transactional flows, but external systems require additional coordination. [10]

Why use a DLQ?

A DLQ isolates messages that remain unprocessable after retries so they do not block normal traffic and can be diagnosed. [3][8]

What does Transactional Outbox solve?

It prevents a successful database write from being separated from the event that should describe it by writing both records in one local transaction. [14]

Is CloudEvents an event broker?

No. CloudEvents standardizes event metadata and representation, including attributes such as id, source, specversion and type; it does not provide transport. [15]

Sources and references

  1. Microsoft Azure Architecture Center, Event-Driven Architecture Style↩1↩2
  2. Microsoft Azure Architecture Center, Publisher-Subscriber Pattern↩1↩2↩3↩4↩5↩6
  3. Microsoft Azure Architecture Center, Queue-Based Load Leveling Pattern↩1↩2↩3↩4↩5↩6
  4. Microsoft Azure Architecture Center, Competing Consumers Pattern↩1↩2↩3↩4↩5
  5. RabbitMQ Documentation, Exchanges↩1↩2↩3↩4
  6. RabbitMQ Documentation, Queues↩1↩2
  7. RabbitMQ Documentation, Consumer Acknowledgements and Publisher Confirms↩
  8. RabbitMQ Documentation, Quorum Queues↩1↩2
  9. Apache Kafka 4.1 Documentation, Introduction↩1↩2↩3↩4↩5↩6↩7↩8↩9↩10
  10. Apache Kafka 4.1 Documentation, Design↩1↩2↩3↩4↩5↩6↩7↩8
  11. Apache Kafka 4.1 KafkaConsumer API↩1↩2
  12. NATS Documentation, Queue Groups↩1↩2↩3↩4
  13. NATS Documentation, JetStream↩1↩2↩3↩4↩5↩6↩7↩8↩9↩10
  14. AWS Prescriptive Guidance, Transactional Outbox Pattern↩1↩2↩3
  15. CloudEvents Specification↩1↩2

Was this helpful?

Get new articles by email

One short email per new Learning article. No spam, unsubscribe in one click.

We only use your email to send new articles. No third-party sharing.

Back to Learning