Scrivio Interview library
ConceptIntermediate6 min read · updated 12 November 2026

For each of these needs, would you choose Kafka or RabbitMQ and why: (1) task queue for image processing with per-message retries, (2) event history that new services can replay, (3) routing to many queues by flexible patterns, (4) 500,000 events per second of clickstream?

For the image-processing task queue we would choose RabbitMQ, because per-message acknowledgements, retries and dead-lettering fit independent jobs. For a replayable event history we would choose Kafka, whose retained log lets a new consumer start from any offset. For routing to many queues by patterns we would choose RabbitMQ, whose exchanges and bindings route on the broker. For 500,000 clickstream events per second we would choose Kafka, whose partitioned, batched log handles that throughput comfortably. RabbitMQ streams and Kafka share groups narrow these gaps, so we check their maturity in our versions.

Why this question is asked

Kafka and RabbitMQ are both called message brokers, but they are built on different ideas, and that difference decides which one fits a need. Interviewers ask questions like this to see whether we choose from the model rather than from habit. In this answer, we will recap the two models, then go through the four needs one at a time with the reason for each choice, and finally look at the features that blur the line between them.

1A Quick Recap of the Two Models

RabbitMQ is a queue broker. Producers publish messages to an exchange, a router that copies each message into the queues whose bindings match it. Consumers take messages from a queue, and each message is acknowledged on its own; once acknowledged, it is removed. The broker tracks the state of every message: delivered, unacknowledged, rejected, dead-lettered.

Kafka is a distributed log. A topic is split into partitions, and each partition is an append-only file of records kept for a set time or size, whether consumed or not. Consumers do not remove records; each consumer group simply remembers an offset, its position in each partition. Records are read in batches in partition order, which is what makes Kafka very fast, but it also means there is no per-record acknowledgement: committing offset 100 means everything before it is done.

Four needs and the better fit
NeedChoiceDeciding feature
Image-processing task queueRabbitMQper-message ack, retry, dead-letter
Event history to replayKafkaretained log, read from any offset
Routing by flexible patternsRabbitMQtopic and headers exchanges
500,000 clickstream events per secondKafkapartitions and batching
Each choice follows from the model, not from a benchmark.

2Need 1: A Task Queue for Image Processing

Each image job is independent, can take seconds, and may fail on its own, for example because one file is corrupt. RabbitMQ handles each message individually: a worker acknowledges a job when it finishes, a crashed worker's unacknowledged jobs go back to another worker, and a job that keeps failing can be dead-lettered to a separate queue after a few attempts. A prefetch limit of 1 or 2 per worker keeps a slow job from holding a pile of waiting ones.

Java
@RabbitListener(queues = "images.resize")
public void resize(ImageJob job) {
images.resize(job.path()); // throws on a corrupt file
}
// spring.rabbitmq.listener.simple.prefetch=1
// spring.rabbitmq.listener.simple.retry.enabled=true
// spring.rabbitmq.listener.simple.retry.max-attempts=3
// after 3 attempts the message is rejected and goes to the queue's dead-letter exchange

Kafka can do this, but less naturally. Because offsets are committed in order, one slow or failing record holds up the records after it in the same partition, and retries need extra retry topics. That is real work to build for what RabbitMQ gives directly.

3Need 2: An Event History That New Services Can Replay

Here the model points the other way. A new service that joins next year wants to read every OrderPlaced event since the beginning. In RabbitMQ, a message is gone once it is acknowledged, so there is nothing to replay. In Kafka, the records are still in the log. A new consumer group with auto.offset.reset=earliest starts at offset 0 and reads the whole history, while existing groups are unaffected.

Java
props.put(ConsumerConfig.GROUP_ID_CONFIG, "recommendations-v1"); // a brand-new group
props.put(ConsumerConfig.AUTO_OFFSET_RESET_CONFIG, "earliest");
// first poll returns records from offset 0 of every partition
// topic config: retention.ms=-1 keeps records forever, or cleanup.policy=compact keeps the latest per key

Notice that retention is a topic setting. For a true history we keep records forever or use log compaction, which keeps the latest record for each key. Either way, the log is the source of the replay.

4Need 3: Routing to Many Queues by Flexible Patterns

Suppose events carry routing keys such as order.eu.created and order.us.cancelled, and different teams want different slices: all EU events, all cancellations, everything. In RabbitMQ, a topic exchange routes on the broker with binding patterns, where * matches one word and # matches zero or more. Each team binds its own queue with its pattern, and receives only what it asked for.

Java
BindingBuilder.bind(euQueue).to(orders).with("order.eu.*"); // order.eu.created, order.eu.cancelled
BindingBuilder.bind(cancelQueue).to(orders).with("order.*.cancelled"); // order.eu.cancelled, order.us.cancelled
BindingBuilder.bind(auditQueue).to(orders).with("order.#"); // every order event

Kafka has no broker-side routing. Every consumer reads the whole topic and filters in its own code, or a stream processor copies events into narrower topics. For many slices that change often, RabbitMQ's bindings are much simpler.

5Need 4: 500,000 Clickstream Events per Second

At 500,000 events per second of about 1 KB each, we move about 500 MB per second. Kafka is built for this: producers send compressed batches, brokers append them to files sequentially, and the load spreads over partitions and brokers. With 60 partitions, each one handles under 10,000 events per second, which is light work, and consumers scale by adding instances up to the partition count. RabbitMQ classic and quorum queues track each message individually, which caps a single queue at far less, so we would have to spread the load over many queues and give up most of what made RabbitMQ attractive.

6Where the Line Is Blurring

Both systems have grown toward each other. RabbitMQ streams, added in 3.9, are an append-only log inside RabbitMQ with replay by offset and much higher throughput than queues. Kafka share groups (KIP-932) let several consumers take records from the same partition with per-record acknowledgement, which is queue-like behaviour for Kafka; they arrived as an early feature in the Kafka 4 line. Before relying on either for the cases above, we check how mature it is in the versions we run and whether our client libraries support it.

7Follow-up questions

Could one Kafka cluster handle all four needs?

It could, with effort: retry topics and dead-letter topics for the task queue, consumer-side filtering or extra topics for routing. Many companies do this to run only one platform. The cost is building and maintaining what RabbitMQ provides directly, so it is a trade between platform count and fit.

Why does a slow record block others in Kafka?

Because a consumer group commits a single offset per partition, meaning everything before it is done. If record 500 fails and records 501 to 510 succeed, the consumer cannot commit past 500 without losing it, so it retries 500 while the later records wait, or moves it to a retry topic.

What would make you pick RabbitMQ streams over Kafka for replay?

If the company already runs RabbitMQ well, the history is moderate in size, and only a few consumers replay it, a stream avoids a second platform. For a large, long-lived event backbone with many teams and connectors, Kafka's ecosystem and tooling usually win.

8Conclusion

In this answer, we chose RabbitMQ for the image task queue because of per-message acknowledgement, retry and dead-lettering, Kafka for the replayable history because its log keeps records and new groups can start from any offset, RabbitMQ for flexible routing because exchanges and bindings filter on the broker, and Kafka for 500,000 clickstream events per second because partitions and batching scale it. RabbitMQ streams and Kafka share groups narrow the gap, but we check their maturity first.

What to say in the interviewAbout 80 seconds aloud

Open with

I'd pick from the model each system is built on. RabbitMQ is a queue broker that tracks every message; Kafka is a partitioned log that keeps records and lets consumers track offsets.

Then, if they want more

For the image task queue I'd choose RabbitMQ: each job is acknowledged on its own, a crashed worker's job goes back to another worker, and after a few failed attempts it's dead-lettered, with a prefetch of one so slow jobs don't hoard work. In Kafka one failing record blocks the rest of its partition unless I build retry topics.

For the event history I'd choose Kafka, because records stay in the log by retention or compaction, so a new service just starts a new consumer group from the earliest offset; in RabbitMQ an acknowledged message is gone.

For routing by patterns I'd choose RabbitMQ: a topic exchange with bindings like order.eu.* or order.# routes on the broker, while Kafka consumers would read everything and filter. For half a million clickstream events a second I'd choose Kafka: compressed batches, sequential writes and maybe sixty partitions make that comfortable, while RabbitMQ queues handle each message individually.

I'd also mention that RabbitMQ streams and Kafka share groups are closing the gap, but I'd check their maturity in our versions first.

About this answer

Last updated
12 November 2026
Checked
Its structure and format are checked automatically. Use it as a carefully prepared study note: where a detail matters, confirm it against the documentation below. What the checks cover
Where the question comes from
Written by Scrivio for practice. It is not taken from an interview.
Official documentation
RabbitMQ documentation
Report an issue with this answer

Copy the line below and send it to the author with what you found. It carries the address of this page.

Issue with "For each of these needs, would you choose Kafka or RabbitMQ and why: (1) task queue for...": https://scrivio-interview-library.netlify.app/spring-boot/rabbitmq-and-jms/fb234b03ac/