跪拜 Guibai
← All articles
Backend · Java · RocketMQ

Kafka vs RocketMQ vs RabbitMQ: The Design Trade-offs Behind the Benchmark Numbers

By Rain的Java大神之路 ·
Read original on juejin.cn ↗ Google Translate ↗ Alt translation

Broker selection mistakes surface during peak traffic as lost orders, blocked queues, and all-night pager rotations. This breakdown ties each broker's internal design to the failure modes that actually break production systems, so teams can pick and configure with the right trade-offs in mind.

Summary

Choosing a message broker by memorizing throughput numbers misses the point. Each of the three major brokers embodies a different message semantic: Kafka is a distributed event log tuned for data flow, RocketMQ is a business message middleware built around transactions and reliability, and RabbitMQ is a flexible routing agent with microsecond latency but weak backlog tolerance. The article argues that the right question is whether a lost message costs money — if yes, use RocketMQ; if it's just logs, use Kafka; if you need fancy routing on light traffic, RabbitMQ is fine.

The breakdown digs into architecture: Kafka's speed comes from sequential disk writes, page cache, batching, and zero-copy sendfile, but those optimizations degrade with TLS, format conversion, or too many partitions. RocketMQ's CommitLog plus ConsumeQueue design gives it Kafka-like write speed while supporting massive business topic counts and billion-level backlogs. RabbitMQ's in-memory queues make it fast at low volume but dangerous under pressure. The article then walks through transactional messages (RocketMQ's half-message and callback check), delayed messages (Queue head-of-line blocking in RabbitMQ, native support in RocketMQ, DIY in Kafka), ordering (local order by key, never global), message loss defense across producer, broker, and consumer, idempotency on the consumer side, and backlog emergency procedures.

Real incident details anchor the advice: a peak of 80k TPS caused RabbitMQ to pile up 3 million messages and crash the consumer; moving the order pipeline to RocketMQ handled the peak with zero loss. The author's team uses RocketMQ for transactions, RabbitMQ for notifications, and Kafka for logs and data lake ingestion.

Takeaways
— RabbitMQ keeps messages in memory by default, so heavy backlog degrades performance and can trigger memory alarms and cluster-wide blocking.
— Kafka's zero-copy sendfile stops working when TLS, message format conversion, or cross-cluster replication is enabled; that's why cloud Kafka throughput can halve.
— RocketMQ's CommitLog + ConsumeQueue design writes all topics sequentially but reads through lightweight indexes, letting it handle billion-level backlogs without performance loss.
— RocketMQ's transaction message uses a half-message stored in an internal topic, then a callback check from the broker guarantees 'local transaction success implies message delivery'.
— For delayed messages, RabbitMQ's TTL approach suffers head-of-line blocking; splitting queues by delay tier or using the delayed message exchange plugin works but the plugin can collapse under load.
— Global ordering requires one queue and one consumer, which collapses throughput to around 1k TPS; local ordering via business key to the same queue/partition is the only practical pattern.
— All MQ products only guarantee at-least-once delivery, so consumer-side idempotency with a unique business key, Redis SETNX, and a DB unique index is mandatory.
— When a backlog hits 3 million messages, don't restart; temporarily scale consumers up to the queue count, or create a new topic with 10x queues and a relay consumer to fast-forward the backlog.
— Kafka's exactly-once semantics only hold within the Kafka-to-Kafka pipeline using read_committed; once messages leave Kafka, exactly-once requires consumer idempotency.
— For RabbitMQ producer reliability, the standard pattern is save message to DB first, send with msgId, confirm callback updates status, return callback catches unroutable messages, and a scheduled task compensates.
Conclusions

The 'does a lost message cost money' heuristic is a practical filter, but it doesn't capture latency-sensitive or routing-heavy workloads where RabbitMQ still wins despite its reliability gaps.

RocketMQ's long-polling pull (holding a request for up to 15 seconds) is a clever middle ground that most Western developers overlook, since Kafka's pure pull and RabbitMQ's push both have obvious downsides.

The article's emphasis on monitoring consumer lag instead of TPS is a common blind spot; teams often report healthy TPS while a dead-letter topic silently grows.

Kafka's deliberate omission of delayed messages and business transaction messages reinforces that it's optimized for data pipelines, not business semantics; teams forcing Kafka into transaction roles end up building fragile compensations.

Concepts & terms
Half message
In RocketMQ's transaction message flow, a half message is written to an internal topic before the local transaction executes. It is invisible to consumers until the transaction commits; if the transaction rolls back, the half message is discarded.
Transactional Outbox
A pattern where business data and an outbox message are written in the same local database transaction. A separate process reads the outbox and publishes to the MQ, guaranteeing no message loss without distributed transactions.
Consumer lag
The difference between the latest message offset a broker has and the offset a consumer group has processed. A growing lag indicates the consumer can't keep up with production, often a precursor to backlog and outages.
Rebalance storm
When Kafka consumers frequently join or leave, or take too long between polls, the group triggers repeated partition rebalances, causing duplicate consumption and throughput collapse.
Long polling pull
A consumer pulls from the broker, and if no message is available, the broker holds the request for a few seconds (RocketMQ defaults to 15s) instead of returning immediately, combining the efficiency of pull with the low latency of push.
Source: juejin.cn ↗ Google Translate ↗ Backup ↗