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
| Model | Who receives it | History and replay | Best fit |
|---|---|---|---|
| Queue | One of the competing workers | Usually not the primary goal | Work distribution and load leveling |
| Pub/Sub Event Bus | Every independent subscription | Depends on broker | Notify many systems |
| Durable Stream | Consumers track their own positions | Yes, according to retention | Replay, 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
| Product | Core model | Strength | Main caveat |
|---|---|---|---|
| RabbitMQ | Exchanges, queues and optional streams | Routing, work queues, pub/sub, ack/confirm | Semantics depend on queue/stream type and configuration |
| Apache Kafka | Partitioned durable log | Retention, replay, consumer groups, high throughput | Ordering is per partition and exactly-once has a defined scope |
| NATS Core + JetStream | Lightweight pub/sub, queue groups, JetStream for persistence | Simple messaging, low latency, optional durability | Core 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
| Need | Natural model | Why |
|---|---|---|
| One task should be handled by one worker | Queue | Competing consumers distribute work |
| Many systems react to one event | Pub/Sub Event Bus | Each subscription receives its own copy |
| History and reprocessing | Durable Stream | Retention and consumer position enable replay |
| Different needs in one domain | Combination | Queues 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.
