Kafka vs RabbitMQ

Mid-level Always asked 7 min

On this page

The question

What is the core difference between Kafka and RabbitMQ?

30-second answer

Kafka is a distributed log: producers append records to partitions, records stay for a retention time, and each consumer group pulls them and tracks its own offset. RabbitMQ is a message broker: producers send to exchanges, which route messages into queues; the broker pushes each message to one consumer and deletes it once acknowledged. So Kafka suits streams that many readers replay; RabbitMQ suits tasks routed to workers.

Understand it

The same orders on Kafka and RabbitMQ

Compare

Orders sit in a log for 7 days. Billing and shipping only move their offsets, so analytics, added a week later, starts at offset 0 and reads the history.

View as text

Six orders are published; billing and shipping consume them; a week later an analytics consumer is added. Under the picture, a table of retention, replay and routing.

Kafka: Orders sit in a log for 7 days. Billing and shipping only move their offsets, so analytics, added a week later, starts at offset 0 and reads the history. Kept: 7 days, read or not. Replay: new group reads from 0. Routing: topic and key, then filter.

RabbitMQ: An exchange routes each order to the queues whose binding matches its key, and a queue deletes a message once acknowledged. Analytics, bound later, only gets new orders. Kept: until a consumer acks it. Replay: none: acked means deleted. Routing: exchange matches keys.

Six orders are published; billing and shipping consume them; a week later an analytics consumer is added. Under the picture, a table of retention, replay and routing.

Kafka: Orders sit in a log for 7 days. Billing and shipping only move their offsets, so analytics, added a week later, starts at offset 0 and reads the history. Kept: 7 days, read or not. Replay: new group reads from 0. Routing: topic and key, then filter.

RabbitMQ: An exchange routes each order to the queues whose binding matches its key, and a queue deletes a message once acknowledged. Analytics, bound later, only gets new orders. Kept: until a consumer acks it. Replay: none: acked means deleted. Routing: exchange matches keys.

Takeaway: Kafka keeps a log that every reader moves through at its own offset, so history can be replayed. RabbitMQ routes each message to queues and deletes it once acknowledged, with richer routing per message.

Kafka or RabbitMQ for each need

Build

Four teams need a broker. Give each need the broker that fits it, with the reason.

Drag a piece, or select it and then select a place.

  1. Empty
  2. Empty
  3. Empty
  4. Empty
View as text

Four rows, one per need, each with an empty slot for the broker that fits it. Four teams need a broker. Give each need the broker that fits it, with the reason.

Clickstream, 500,000 events a second: Kafka: partitioned log, huge throughput. Each email job to one free worker: RabbitMQ: work queue, ack per message. Rebuild a read model from last month: Kafka: retention and offset reset. Route orders by country pattern: RabbitMQ: topic exchange bindings.

Kafka where data is a stream to keep, replay and scale; RabbitMQ where each message is a task to route and hand to one worker.

Four rows, one per need, each with an empty slot for the broker that fits it. Four teams need a broker. Give each need the broker that fits it, with the reason.

Clickstream, 500,000 events a second: Kafka: partitioned log, huge throughput. Each email job to one free worker: RabbitMQ: work queue, ack per message. Rebuild a read model from last month: Kafka: retention and offset reset. Route orders by country pattern: RabbitMQ: topic exchange bindings.

Kafka where data is a stream to keep, replay and scale; RabbitMQ where each message is a task to route and hand to one worker.

Takeaway: Choose Kafka for high-volume streams that several readers consume and replay. Choose RabbitMQ for tasks that need per-message routing, acknowledgment and delivery to one worker.

Which broker for this job?If several independent readers need the data, or it must be replayed, or the volume is very high, choose Kafka. If each message is a task for one worker, or needs routing by pattern, priorities or per-message retries, choose RabbitMQ. Many systems use both.yesnoyesnoNew messagingneedReplay, manyreadersor huge volume?Kafka: a logto keep and streamTasks for oneworker,routing, priorities?RabbitMQ: queuesand exchangesEither works:pick what you run
Which broker for this job?If several independent readers need the data, or it must be replayed, or the volume is very high, choose Kafka. If each message is a task for one worker, or needs routing by pattern, priorities or per-message retries, choose RabbitMQ. Many systems use both.yesnoyesnoNew messagingneedReplay, manyreadersor huge volume?Kafka: a logto keep and streamTasks for oneworker,routing, priorities?RabbitMQ: queuesand exchangesEither works:pick what you run
Which broker for this job?

In code

List<TopicPartition> parts = consumer.partitionsFor("orders").stream()
    .map(p -> new TopicPartition("orders", p.partition())).toList();
consumer.assign(parts);                                       // no group rebalancing: we pick the partitions

long weekAgo = Instant.now().minus(Duration.ofDays(7)).toEpochMilli();
Map<TopicPartition, OffsetAndTimestamp> starts =
    consumer.offsetsForTimes(parts.stream().collect(Collectors.toMap(p -> p, p -> weekAgo)));
starts.forEach((p, o) -> {
    if (o != null) consumer.seek(p, o.offset());              // first record at or after that time
    else consumer.seekToEnd(List.of(p));                      // nothing that recent
});
Kafka replay: start a reader at a point in time
@Bean TopicExchange orders() { return new TopicExchange("orders"); }

@Bean Queue shippingEu() { return QueueBuilder.durable("shipping-eu").build(); }

@Bean Binding euOnly(Queue shippingEu, TopicExchange orders) {
    return BindingBuilder.bind(shippingEu).to(orders).with("order.eu.*");
}

// Producer: the routing key decides which queues get a copy
rabbit.convertAndSend("orders", "order.eu.de", new OrderPlaced(42));

@RabbitListener(queues = "shipping-eu")
void ship(OrderPlaced e) { shipping.start(e); }   // acked when this returns, then deleted
RabbitMQ through Spring AMQP (Advanced Message Queuing Protocol): routing by pattern
kafka-consumer-groups.sh --bootstrap-server localhost:9092 --group analytics --topic orders \
  --reset-offsets --to-datetime 2026-11-06T00:00:00.000 --execute
# RabbitMQ has no equivalent for a classic queue: acknowledged messages are gone
Kafka: move a group back to a date and reprocess from there
// autoAck = true: deleted as soon as it is sent to us; if we crash mid-email, it is lost
 Wrong channel.basicConsume("emails", true, deliver, cancel);

// autoAck = false, and ack after the work: unacked messages go back to the queue if we die
 Right channel.basicConsume("emails", false, (tag, msg) -> {
 Right     send(msg);
 Right     channel.basicAck(msg.getEnvelope().getDeliveryTag(), false);
 Right }, cancel);
RabbitMQ auto-ack deletes a message on delivery, so a crash loses it
The same order through each brokerIn Kafka, the producer appends the order to a partition of the topic, and each consumer group reads it at its own offset. In RabbitMQ, the producer sends it to an exchange, which copies it into every queue whose binding matches the routing key, and each queue delivers it to one consumer and deletes it on acknowledgment.RabbitMQKafkaProducerTopic partition,kept for daysEach group readsat its own offsetProducerExchange matchesthe routing keyQueue: oneconsumer,deleted on ack
The same order through each brokerIn Kafka, the producer appends the order to a partition of the topic, and each consumer group reads it at its own offset. In RabbitMQ, the producer sends it to an exchange, which copies it into every queue whose binding matches the routing key, and each queue delivers it to one consumer and deletes it on acknowledgment.RabbitMQKafkaProducerTopic partition,kept for daysEach group readsat its own offsetProducerExchange matchesthe routing keyQueue: oneconsumer,deleted on ack
The same order through each broker

Solve it

Pick the broker for a notification service

A team builds notifications: emails, SMS and push. About 200 per second; each must be sent once, by any free worker; password resets jump the line; a failed send is retried in 1, 5 and 30 minutes. Separately, analytics wants every notification event for 90 days. Choose a broker, or two, and justify it.

  1. Split the two needs. Sending is a task queue: one worker per message, priority, delayed retries, acknowledgment per message. Analytics is a stream: keep 90 days, let readers come and go, replay.
  2. Map tasks to RabbitMQ. A durable queue with competing consumers spreads sends; a priority queue lets resets jump; retries use a dead letter exchange with per-queue TTL (time to live) delays.
  3. Map the stream to Kafka. Workers publish a NotificationSent event to a Kafka topic with 90-day retention; analytics reads it, and can rebuild its numbers by resetting offsets.
  4. Weigh one broker instead. Kafka alone makes priorities and per-message delays awkward; RabbitMQ alone cannot replay 90 days for new readers. Running both costs operations, so say it out loud.
  5. Check. Load test 200 per second with a worker killed mid-send: no notification lost, resets first, and analytics counts match the sends.
@Bean Queue notifications() {
    return QueueBuilder.durable("notifications")
        .maxPriority(10)                                  // password resets published with priority 9
        .deadLetterExchange("notifications.retry")        // a rejected message goes to the retry exchange
        .build();
}

@Bean Queue retryIn1Minute() {
    return QueueBuilder.durable("notifications.retry.1m")
        .ttl(60_000)                                      // waits 1 minute here...
        .deadLetterExchange("")                           // ...then the default exchange
        .deadLetterRoutingKey("notifications")            // puts it back on the work queue
        .build();
}
The sending side on RabbitMQ: priorities, and retries through a dead letter exchange

How to answer

  • Kafka scales by partitions and keeps order per partition.
  • RabbitMQ routes per message with direct, topic, fanout and headers exchanges.
  • RabbitMQ acknowledges and redelivers single messages; Kafka commits a position.
  • Kafka is built for very high throughput and long retention.

Common mistakes

  • Saying one is simply faster or better. They solve different problems, and many systems run both.
  • Claiming RabbitMQ cannot persist messages. Durable queues and persistent messages survive restarts.

Follow-up questions

How do you replay messages in Kafka, and can RabbitMQ do it?

In Kafka, records stay for the retention time, so you move a group's offsets back with kafka-consumer-groups.sh --reset-offsets, to the earliest offset, an offset or a date, or call seek in code, or start a new group. In a classic RabbitMQ queue, an acknowledged message is deleted, so it is gone; replay needs a stream, or the producer to resend from its own store.

  • Replay only reaches as far back as retention.
  • Consumers must tolerate reprocessing, so keep them idempotent.
  • Reset offsets only while the group is stopped.

See it in the infographic: The same orders on Kafka and RabbitMQ

When would you choose Kafka, and when RabbitMQ?

Choose Kafka for event streams: high volume, several independent consumers, replay, ordering per key, stream processing, change data capture, long retention. Choose RabbitMQ for work queues and integration: tasks handed to one worker, routing by pattern, priorities, per-message acknowledgment and redelivery, delays, request and reply. At low volume both work; then the team's experience and what already runs matter most.

  • Event-driven microservices that publish domain events lean towards Kafka.
  • Background jobs with retries and priorities lean towards RabbitMQ.
  • Managed services, such as Amazon MSK (Managed Streaming for Apache Kafka) or CloudAMQP, change the operating cost.

See it in the infographic: Kafka or RabbitMQ for each need

How does RabbitMQ route messages?

A producer publishes to an exchange with a routing key; it never writes to a queue directly. Bindings connect queues to exchanges. A direct exchange matches the key exactly, a topic exchange matches patterns such as order.eu.*, a fanout exchange copies to every bound queue, and a headers exchange matches message headers. Each matching queue gets its own copy, and its consumers compete for the messages in it.

  • One queue with several consumers spreads work; one queue per service broadcasts.
  • A message that matches no binding is dropped, unless it is marked mandatory or an alternate exchange is set.
  • A dead letter exchange catches rejected or expired messages.

See it in the infographic: The same orders on Kafka and RabbitMQ

How do Kafka and RabbitMQ scale consumers differently?

RabbitMQ uses competing consumers: any number can read one queue, each message goes to one of them, and prefetch limits how many unacknowledged messages each holds. So you just add workers, and order is not kept across them. Kafka assigns whole partitions to consumers of a group, so parallelism stops at the partition count, but each partition keeps its order.

  • Kafka trades flexible scaling for ordering per partition.
  • RabbitMQ prefetch, often 10 to 100, balances throughput and fairness.
  • Kafka share groups, new in Kafka 4, bring queue-like consumption to Kafka.

See it in the infographic: Kafka or RabbitMQ for each need

How do Kafka and RabbitMQ make sure a message is not lost?

Both need cooperation from both ends. In Kafka, the producer uses acks=all on a topic with replication factor 3 and min.insync.replicas=2, and the consumer commits after processing. In RabbitMQ, the producer uses publisher confirms with durable, replicated quorum queues and persistent messages, and the consumer acknowledges manually after processing. Both then deliver at least once, so consumers must be idempotent.

  • RabbitMQ auto-ack deletes on delivery, so a crash loses the message.
  • Quorum queues replicate with Raft, as KRaft does for Kafka metadata.
  • Unacknowledged RabbitMQ messages are redelivered when the consumer's channel closes.

See it in the infographic: The same orders on Kafka and RabbitMQ

Does RabbitMQ have anything like Kafka's log?

Yes: RabbitMQ streams, since version 3.9, are an append-only, replicated log that consumers read from an offset without deleting, with retention by size or age. They narrow the gap for replay, but Kafka's ecosystem for stream processing, connectors and schema handling is larger.

Check yourself

1. A new service needs every order from the past 5 days. Which setup gives it that without asking producers to resend?
Show answers
  • A Kafka topic with 7-day retention: Correct. The records are still in the log, and a new group can read from the start.
  • A new RabbitMQ classic queue bound to the orders exchange: Incorrect. A new queue only receives messages published after its binding.
  • Reading the existing RabbitMQ billing queue: Incorrect. Billing acknowledged those messages, so they were deleted.
2. Orders must reach different teams based on keys such as order.eu.de or order.us.ny, with wildcards per region. What fits most directly?
Show answers
  • A RabbitMQ topic exchange with bindings like order.eu.: Correct. Pattern matching on routing keys is what a topic exchange does.
  • One Kafka partition per country: Incorrect. Partitions are for parallelism; keys map to them by hash, not by pattern.
  • A RabbitMQ fanout exchange: Incorrect. Fanout ignores the routing key and copies to every queue.
3. Ten workers share a stream of jobs on a Kafka topic with 3 partitions, all in one consumer group. How many workers can be busy at once?
Show answers
  • 3: Correct. Each partition goes to one consumer of the group; the other 7 idle.
  • 10: Incorrect. That is how competing consumers on a RabbitMQ queue would behave.
  • 1: Incorrect. A group spreads partitions over its consumers, so up to 3 work.