In brief
Kafka is a distributed event log: messages are stored for a set period, many consumers read them independently and can go back to any point. RabbitMQ is a broker with queues: a message goes into a queue according to routing rules, a consumer processes and acknowledges it, and the broker removes it. Choose Kafka for event streams with many consumers, replaying history and high volumes. Choose RabbitMQ for tasks that someone must do once, with complex routing and retries. Both technologies now have features that bring them closer together.
Two models: the log and the queue
The difference starts with what happens to a message after it is read.
Kafka writes events to topics split into partitions. Each partition is a log that is appended to at the end. A consumer remembers its position (offset) and decides what to read. An event does not disappear after reading: it stays as long as the retention policy says, for example 7 days or up to a size limit. Ten systems can read the same topic at their own pace, and a new system can read the history from the beginning.
RabbitMQ receives messages on exchanges, which route them to queues according to bindings. A consumer takes a message, processes it and acknowledges it, and the broker removes it from the queue. A queue is meant to stay mostly empty: a message is a task to do, not an entry in a history.
| Kafka | RabbitMQ | |
|---|---|---|
| Model | an event log with retention | a broker with queues |
| After reading | the message stays | the message is gone after acknowledgement |
| Many consumers | each reads the same log independently | each needs its own queue or a stream |
| Replaying history | yes, from a chosen point | not in classic queues, yes in streams |
| Ordering | within a partition | within a queue, with a single consumer |
| Routing | by topic and partition key | exchanges: direct, topic, fanout, headers |
| Scale | high volumes, long retention | many queues, complex routing, lower volume per queue |
When Kafka
- Many consumers of the same event. "Order placed" is read by the warehouse, invoicing, CRM and the data warehouse, each at its own pace.
- Replay. A new system or a fixed consumer goes through the events of recent days and rebuilds its state.
- Data streams. Machine readings, application events, database changes through change data capture.
- Ordering for one object. Events with the same key (for example an account number) go to one partition and are read in order.
Since version 4.0, Kafka runs only in KRaft mode, without a separate ZooKeeper cluster, which simplifies operations. The same version introduced share groups in early access, which bring queue-style consumption to regular topics. Before relying on this feature, check its status in the version you deploy. More about Kafka itself in Apache Kafka in the enterprise.
When RabbitMQ
- Tasks to be done once. Generate an invoice PDF, send an email, recalculate an order. Someone has to do it, acknowledge it and move on.
- Complex routing. Messages routed by type, country, priority or headers to different queues, without code in the application.
- Retries and error queues. A message that failed is retried with a delay or goes to a dead letter queue for investigation.
- Many small integrations. Dozens of low-traffic queues, for example messages to partner systems.
For replicated queues, RabbitMQ recommends quorum queues. The older classic mirrored queues were removed in version 4.0, which matters when upgrading older installations. RabbitMQ also has streams: a log with retention and non-destructive reads, which allows replay and serving many consumers.
Delivery guarantees: what you have to do yourself
Whichever you choose, most integrations run "at least once". A message can arrive twice, for example when a consumer processes it but fails before acknowledging. That is why:
- The consumer is idempotent. For each message it checks the event ID and never creates the same invoice twice.
- The producer uses the outbox pattern. The database write and the message to send go into one transaction, and a separate process sends messages from the outbox table. Without it, an order can be saved while the event about it is lost.
- Errors have a place to go. A dead letter queue or a separate topic for failed events, with an alert and an investigation procedure.
- Lag is monitored. In Kafka, the gap between the last written and last read offset; in RabbitMQ, queue length and the age of the oldest message.
Asynchronous processing in general is covered in Queues and asynchronous processing.
Example decisions and operations
| Situation | Choice | Why |
|---|---|---|
| payment events read by several systems, with audit | Kafka | many consumers, replay, ordering per account |
| machine data from the line for OEE reports | Kafka | a steady stream, several consumers |
| orders from a portal into the ERP with retries | RabbitMQ | a task done once, an error queue |
| generating documents and sending emails in the background | RabbitMQ | simple tasks, routing by type |
| the company already runs RabbitMQ and needs one replayable stream | a RabbitMQ stream | no second technology to operate |
Operating cost counts as much as performance. A Kafka cluster needs planning for partitions, retention and disk space. RabbitMQ is usually simpler to start with, but large queue backlogs require watching memory and disk. Both are available as managed cloud services. Performance is worth checking before launch, as described in Kafka performance testing.
An example from banking: replacing an ESB with a Kafka event platform for payments, carried out with the strangler fig pattern. We design and build such platforms in our System integration service.
Questions and answers
Will Kafka replace RabbitMQ in every use case?
No. Kafka handles event streams and many consumers well, but routing by headers, delayed retries or many small task queues are easier to build in RabbitMQ. Share groups bring Kafka closer to queues, but it is a new feature you need to verify in your version.
Can a company use both Kafka and RabbitMQ?
Yes, and it can be sensible: Kafka as the event backbone between domains, RabbitMQ for tasks inside one application. Each technology, however, means separate operations, monitoring and team skills. Add the second one only when the first clearly does not fit the need.
Does a messaging system guarantee a message arrives exactly once?
In integration between systems you have to assume a message may arrive more than once. Kafka has transactions and an idempotent producer, but an "exactly once" effect across the whole process, including the write in the consumer's database, comes only from an idempotent consumer and the outbox pattern on the producer side.
Where do you start migrating off an old integration bus?
With a map of flows: who sends, who receives, what volume, what ordering and replay requirements. Then you move one flow at a time, with the old and new paths running in parallel. The approaches are compared in ESB vs event-driven architecture.