Dev tools
Kafka vs RabbitMQ: Which Message Broker to Use
Kafka vs RabbitMQ: log vs queue, routing, ordering, delivery, scaling, operations, Kafka vs RabbitMQ use cases, plus SQS, and when to use each one.
In Kafka vs RabbitMQ, Apache Kafka is a distributed event log: it appends messages to partitioned topics, keeps them for a set retention period after they're read, and lets many consumer groups read and replay the same stream at very high throughput. RabbitMQ is a message broker: it routes each message through exchanges into queues, delivers it to a consumer, and deletes it once acknowledged, with flexible routing, per-message features and many protocols. Choose Kafka for event streaming, data pipelines and replay; choose RabbitMQ for task queues, complex routing and request-style messaging between services.
This guide explains the difference between Kafka and RabbitMQ in architecture, routing, ordering, delivery guarantees, scaling and operations, walks through Kafka vs RabbitMQ use cases with a worked example, adds Amazon SQS to the comparison, and ends with a clear answer on when to use Kafka and when to use RabbitMQ.
Kafka vs RabbitMQ at a Glance
| Apache Kafka | RabbitMQ | |
|---|---|---|
| Core model | Distributed, partitioned, replicated log | Message broker with exchanges and queues |
| What happens after a read | Message stays until retention expires; consumers track their own position (offset) | Message is removed once the consumer acknowledges it |
| Replay | Yes: any consumer can re-read from an earlier offset | Not for classic and quorum queues; yes with RabbitMQ streams |
| Routing | Producer chooses a partition, usually by hashing a key | Broker routes via exchanges (direct, topic, fanout, headers) and bindings |
| Ordering | Guaranteed within a partition | Guaranteed within a queue (with one consumer) |
| Consumers | Consumer groups; each partition read by one member of a group (share groups add queue-like sharing) | Competing consumers on a queue; push-based delivery |
| Per-message features | Limited | TTL, priorities, dead-letter exchanges, delayed delivery (via plugin) |
| Protocols | Kafka's own binary protocol | AMQP 1.0, AMQP 0-9-1, MQTT, STOMP, plus a stream protocol |
| Throughput | Very high, built for streaming | High; lower than Kafka for large streams |
| Coordination | KRaft (built-in); ZooKeeper removed in Kafka 4.0 | Built-in clustering; quorum queues use Raft |
| Ecosystem | Kafka Connect, Kafka Streams, schema registries, stream processors | Client libraries in most languages, management UI, plugins |
| License | Apache 2.0 | Mozilla Public License 2.0 |
| Best for | Event streaming, analytics pipelines, event sourcing, logs | Background jobs, task distribution, complex routing, IoT via MQTT |
What Is Kafka?
Apache Kafka started at LinkedIn and became an Apache project in 2011. Its documentation describes the core idea plainly: events are "organized and durably stored in topics," a topic is spread across partitions on different brokers, and "events are not deleted after consumption." Instead, you set how long Kafka keeps them per topic.
Every new event is appended to one partition of a topic. Events with the same key, such as a customer ID, always go to the same partition, and any consumer of that partition reads its events "in exactly the same order." Consumers belong to consumer groups; each group gets the full stream, and within a group the partitions are split among members. Because the data stays on disk, a new service can start reading from the beginning and catch up on history.
Kafka 4.0, released in March 2025, was the first major release to run entirely without Apache ZooKeeper; clusters now use Kafka's built-in KRaft consensus. Newer releases add share groups (KIP-932, "Queues for Kafka"), which let several consumers share a partition and acknowledge messages individually; Apache Kafka 4.2 lists them among its features and Confluent describes them as production-ready.
What Is RabbitMQ?
RabbitMQ, first released in 2007, is a general-purpose message broker. Producers publish messages to an exchange, which routes them to one or more queues according to bindings. Consumers receive messages from queues and acknowledge them; acknowledged messages are removed.
The exchange types give RabbitMQ its flexibility:
- Direct: route by exact routing key, such as
invoice.created. - Topic: route by wildcard patterns, such as
orders.*.eu. - Fanout: copy every message to all bound queues.
- Headers: route by message header values.
RabbitMQ 4.0 removed classic queue mirroring in favor of quorum queues, which replicate messages with the Raft consensus algorithm, and made AMQP 1.0 a core protocol. Since version 3.9, RabbitMQ also offers streams, an append-only, replayable log similar in spirit to Kafka topics. Per-message features such as time-to-live, priorities and dead-letter exchanges make it well suited to task-style work.
The Difference Between Kafka and RabbitMQ
Log vs queue
This is the heart of it. In RabbitMQ, a message is a unit of work: once a consumer handles it, it's gone. In Kafka, a message is an entry in a history: reading it doesn't remove it, and anyone can read it again. RabbitMQ's own comparison page puts it this way: "In Kafka, a message is a position in a shared log. In RabbitMQ, a message is an independent item of work."
Where routing happens
Kafka keeps the broker simple: the producer chooses the partition, usually by key hash, and consumers subscribe to whole topics. RabbitMQ puts routing in the broker, so you can change who receives what by changing bindings, without touching producers. If your routing rules are complex or change often, RabbitMQ is easier.
Consumer model and scaling
In Kafka's classic consumer groups, each partition is read by one consumer in a group, so the number of partitions caps how many consumers in a group can work in parallel. A topic with 12 partitions can keep at most 12 consumers in one group busy. RabbitMQ scales consumers simply by adding more competing consumers to a queue. Kafka's share groups narrow this gap by letting several consumers share a partition.
Ordering
Kafka guarantees order within a partition, so you choose a key (an account or device ID) to keep related events in order while still spreading load. RabbitMQ keeps order within a queue, but with several competing consumers, messages finish in a different order than they arrived.
Delivery guarantees
Both default to at-least-once delivery when used correctly: RabbitMQ with publisher confirms and consumer acknowledgments, Kafka with replicated topics and committed offsets. Kafka also supports idempotent producers and transactions for exactly-once processing within Kafka-to-Kafka pipelines. In both systems, consumers that touch external systems should be idempotent, because duplicates can still happen.
Retention and storage
Kafka is built to store large volumes for days, weeks or indefinitely, which suits analytics and auditing. RabbitMQ queues are meant to stay short: a growing backlog is a sign consumers can't keep up. RabbitMQ streams are the exception, designed for retention and replay.
Protocols and clients
RabbitMQ speaks several open protocols, including AMQP and MQTT, which makes it popular for IoT devices and mixed-language environments. Kafka uses its own protocol, with official and community clients for most languages, and connects to databases and SaaS tools through Kafka Connect.
Kafka vs RabbitMQ Use Cases
| Use case | Better fit | Why |
|---|---|---|
| Background jobs (emails, thumbnails, AI tasks) | RabbitMQ | Simple work queues, acks, retries, dead-lettering |
| Event streaming between many services | Kafka | Many consumer groups read the same events independently |
| Analytics and data pipelines into a warehouse or lake | Kafka | High throughput, retention, Kafka Connect |
| Event sourcing and audit logs | Kafka | Durable, ordered, replayable history |
| Complex routing by type, region or priority | RabbitMQ | Topic and headers exchanges, bindings change at runtime |
| IoT devices sending telemetry over MQTT | RabbitMQ | Native MQTT support |
| Request/reply between services | RabbitMQ | Reply-to queues and correlation IDs are built-in patterns |
| Log aggregation and metrics streams | Kafka | Massive append-only volume |
| Change data capture from databases | Kafka | Connectors stream database changes as events |
| Delayed or scheduled jobs | RabbitMQ | Per-message TTL and delayed-message plugin |
| Event-driven architecture at large scale | Kafka | Topics as the system's shared event history |
Worked example: one "order placed" event, three services
An e-commerce company needs billing, email and analytics to react to every order, and next quarter it wants to add a fraud-detection service.
With RabbitMQ: the checkout service publishes order.placed to a fanout (or topic) exchange. Three queues are bound to it, one per service, and each service's workers consume from their queue. Adding fraud detection means binding a fourth queue; it receives orders from that moment on, but not past orders.
With Kafka: checkout publishes to an orders topic keyed by customer ID. Billing, email and analytics are three consumer groups reading the same topic at their own pace. Adding fraud detection means starting a fourth consumer group, which can read from the earliest retained offset and backfill its model on past orders before switching to live data.
| RabbitMQ | Kafka | |
|---|---|---|
| Adding a consumer | Bind a new queue | Start a new consumer group |
| History for the new consumer | None | Everything still within retention |
| Per-order work distribution | Built in (competing consumers per queue) | By partition; plan partition count ahead |
| Retrying a failed email | Requeue or dead-letter exchange | Retry topic or separate handling |
Both work. If replaying history matters, Kafka wins; if the job is mostly distributing tasks with retries, RabbitMQ is simpler.
Kafka vs RabbitMQ vs SQS
Many teams on AWS also consider Amazon SQS, a fully managed queue.
| Kafka | RabbitMQ | Amazon SQS | |
|---|---|---|---|
| Model | Event log | Broker with queues | Managed queue |
| Operations | Self-managed or managed (Confluent Cloud, Amazon MSK) | Self-managed or managed (Amazon MQ, CloudAMQP) | None: fully serverless |
| Replay | Yes | Streams only | No |
| Routing | By partition key | Rich exchange routing | None; pair with SNS for fan-out |
| Ordering | Per partition | Per queue | Standard: best effort; FIFO: per message group |
| Message size | Configurable (1 MB default) | Configurable | Up to 1 MiB |
| Retention | Configurable, can be long | Until consumed (streams: configurable) | 4 days default, up to 14 |
| Best for | Streaming at scale | Flexible messaging, protocols | Simple background jobs on AWS |
Similar comparisons apply to Azure Service Bus (an enterprise broker closer to RabbitMQ), Google Cloud Pub/Sub (managed pub/sub with replay features), NATS JetStream (lightweight streaming) and Redis-based job queues for small apps.
Operations and Cost
Running either yourself is real work.
- Kafka needs capacity planning for partitions, disk and replication, monitoring of consumer lag and broker health, and careful upgrades. KRaft removed the separate ZooKeeper cluster, which simplified operations, but large clusters still need expertise. Managed services trade money for that effort.
- RabbitMQ is generally simpler to start, with a built-in management UI. At scale you'll tune quorum queues, memory and disk alarms, and connection counts.
Cost follows usage. Kafka's storage grows with retention and replication: one terabyte of events a day, retained for seven days with three replicas, means about 21 TB of disk before compression. RabbitMQ stays cheap when queues stay short, and gets expensive in memory and disk when backlogs pile up.
When to Use Kafka and When to Use RabbitMQ
Use Kafka when:
- Several independent systems need the same stream of events.
- You need to replay or reprocess history, or add new consumers that backfill.
- Volume is very high, such as clickstreams, logs, metrics or IoT telemetry at scale.
- You're building data pipelines or stream processing with Kafka Connect and Kafka Streams.
- Events are your system's source of truth (event sourcing).
Use RabbitMQ when:
- You're distributing tasks to workers with acknowledgments and retries.
- You need flexible routing that changes without code changes.
- You need per-message TTL, priorities, delays or dead-letter handling.
- Devices or legacy systems speak MQTT, STOMP or AMQP.
- You want something simpler to run for moderate volumes.
Use both when it fits: many companies use Kafka as the central event backbone and RabbitMQ (or a cloud queue) for job queues inside individual services. If you're deploying either on your own infrastructure, our comparison of Docker vs Kubernetes covers the container platforms most teams run them on.
Common Mistakes
- Using Kafka as a simple job queue. Classic consumer groups make per-message retries and work sharing awkward; RabbitMQ or SQS is simpler for jobs.
- Using RabbitMQ as a data lake. Long queues hurt performance; use streams or Kafka for retained history.
- Too few Kafka partitions. Partitions cap consumer parallelism in a group; increasing them later changes key-to-partition mapping.
- Ignoring ordering keys. Without a key, related Kafka events land in different partitions and lose order.
- No dead-letter handling. In RabbitMQ use dead-letter exchanges; in Kafka, design retry and dead-letter topics.
- Non-idempotent consumers. At-least-once delivery means duplicates; make processing safe to repeat.
- Picking based on benchmarks alone. Most applications are far below either system's limits; fit with your use case matters more.
For synchronous calls between services, where the caller needs an immediate answer, a broker is the wrong tool; our guide to gRPC vs REST covers request-response APIs. And for caching or lightweight queues inside one app, see Redis vs Valkey.
FAQ
Is Kafka better than RabbitMQ?
Neither is better overall. Kafka is better for high-volume event streaming, retention and replay. RabbitMQ is better for task queues, flexible routing and per-message features. The right choice depends on whether your messages are events to keep or jobs to complete.
Is Kafka a message queue?
Traditionally, no: it's a distributed event log where messages stay after they're read. Newer Kafka versions add share groups that provide queue-like consumption, but RabbitMQ and SQS remain closer to classic message queues.
Can RabbitMQ replace Kafka?
For moderate volumes and when you need replay, RabbitMQ streams cover some Kafka use cases. For very large streaming pipelines with a broad connector and stream-processing ecosystem, Kafka remains the stronger choice.
Which is faster, Kafka or RabbitMQ?
Kafka generally handles much higher throughput for large streams thanks to its append-only log and batching. RabbitMQ can offer low latency for individual messages at moderate volumes. Real performance depends on configuration, message size and durability settings.
Should I use Kafka for microservices?
Use Kafka when microservices share events and need history or many consumers. Use RabbitMQ or a cloud queue for task distribution between services, and direct API calls when a service needs an immediate response.