Skip to content

Checking your reading list…

Retry

Stay curious. Build better.

Appearance

Choose how BestHub looks on this device.

Changes apply immediately.

Search articles

Open Discover with these filters

Suggested searches

MQ Selection: Three Questions That Decide 80% of Your Choice

This article provides a practical framework for selecting a message queue by first answering three critical questions about message loss tolerance, semantic requirements, and operational capacity, then comparing RabbitMQ, Kafka, and RocketMQ across six dimensions, highlighting why backlog capacity matters more than throughput, and listing five real-world anti-patterns to avoid.

Introduction

The most common mistake in MQ selection isn't picking the wrong product—it's not making a deliberate choice at all. Teams often default to whatever they used before (RabbitMQ or Kafka) and only discover mismatches when they need features like delayed messages, transactional messaging, or backlog handling, by which time migration costs are high.

Three Questions That Decide 80% of the Decision

Before looking at any comparison table, answer these three questions:

1. What happens if a message is lost? Logging/metrics loss is acceptable; order/payment message loss costs money. This defines your reliability investment.

2. Are there special semantic requirements? Delayed delivery, transactional messages, strict ordering, priority queues, broadcast routing—each requirement eliminates a batch of candidates. This is often overlooked early and hardest to add later.

3. Who operates it and who fixes issues? More components and heavier deployments mean higher long-term costs. Large companies often ignore this; for small teams it can be fatal.

Quick Reference: Match Your Scenario to the Right MQ

Business messages (orders/payments/inventory) needing delayed or transactional messages → RocketMQ

Logs, metrics, CDC, stream processing needing throughput and replay → Kafka

Business decoupling + complex routing, small team, want fast launch → RabbitMQ

Already have Redis, just need a lightweight async queue → Redis Stream (don't use as primary queue)

On cloud and don't want to self-manage → Cloud vendor managed service

Six Comparison Dimensions (Weighted by Importance)

1. Message Semantics: Delayed, Transactional, Ordering (Highest Weight)

Delayed messages: RabbitMQ simulates via TTL + dead-letter (head-of-line blocking if queue long) or plugins; Kafka does not support ; RocketMQ native (4.x: 18 fixed levels, 5.x: arbitrary duration).

Transactional messages: RabbitMQ none ; Kafka none ; RocketMQ native (half-message + broker check-back).

Ordered messages: RabbitMQ only with single queue + single consumer; Kafka per-partition ordering (sacrifices throughput); RocketMQ partition-ordered / globally-ordered.

Priority queues: RabbitMQ yes ; Kafka no ; RocketMQ no .

If your requirements include "auto-cancel unpaid orders after 30 minutes," this table alone often decides the choice.

2. Throughput and Backlog Capacity

Single-node throughput: RabbitMQ ~10k/sec; Kafka ~1M/sec; RocketMQ ~100k/sec.

Backlog capacity: RabbitMQ weak —performance degrades visibly when backlogged; Kafka strong —sequential disk write + retention policies; RocketMQ strong —CommitLog sequential write.

Backlog capacity matters more than throughput. In spike scenarios, messages piling up to hundreds of thousands is normal; RabbitMQ is the first to buckle even though its steady-state throughput is sufficient. Selecting based only on throughput uses average numbers to judge peak scenarios—wrong direction.

3. Routing Capability

RabbitMQ's Exchange (direct/fanout/topic/headers + bindings) is the most flexible of the three: one event routed by different rules to multiple queues is its home turf. Kafka only has topic + partitions, with each consumer group consuming full data; RocketMQ's Tag filtering is finer than Kafka but far from Exchange flexibility. "One event must be dispatched to five or six downstreams with different rules"—choose RabbitMQ for the smoothest implementation.

4. Reliability and Delivery Semantics

All three can achieve no-loss (producer ack + persistence + consumer manual ack), but differ in out-of-the-box readiness:

RocketMQ: built-in retry (default 16 times) + dead-letter queue, works immediately.

RabbitMQ: must configure retry + dead-letter exchange yourself.

Kafka: no retry/dead-letter concept; relies on business code or extra topics.

Remember: all MQs guarantee at-least-once delivery; duplicate consumption is inevitable. Idempotency is a mandatory requirement for every solution.

5. Operational Cost

Components: RabbitMQ (Broker on Erlang runtime); Kafka (Broker + ZooKeeper, 4.0+ pure KRaft); RocketMQ (NameServer + Broker).

Scaling: RabbitMQ add nodes, queue migration painful; Kafka add brokers triggers partition rebalance; RocketMQ add brokers, queue count must expand too.

High Availability: RabbitMQ mirror queues / Quorum Queue; Kafka multi-replica ISR; RocketMQ master-slave sync / DLedger.

Monitoring: RabbitMQ management plugin UI; Kafka JMX + exporter + Grafana; RocketMQ Dashboard console.

Kafka 4.0 removed ZooKeeper entirely—the old "must run ZK" impression is outdated—but KRaft's operational mental load hasn't decreased much.

6. Ecosystem and Language Support

Java: All three have mature Spring Boot starters; no practical difference.

Multi-language: RabbitMQ (AMQP) and Kafka clients cover the widest range; RocketMQ's Java client is best, 5.x adds gRPC via Proxy, gap narrowing.

Stream processing: Flink, Spark, CDC ecosystems essentially only recognize Kafka.

Decision Tree

消息丢了会怎样?
├─ 无所谓(日志、埋点、行为流)
│   └─ Kafka(吞吐 + 回溯 + 流计算生态)
│
└─ 不能丢(订单、支付、库存、资金)
    │
    ├─ 要延迟消息 or 事务消息?
    │   └─ 是 → RocketMQ
    │
    ├─ 一条事件要按多种规则分发到多个下游?
    │   └─ 是 → RabbitMQ
    │
    └─ 只是解耦 + 削峰,队列不多
        └─ RabbitMQ

The probability of reaching the last layer is higher than you think. Many small-to-medium projects just need "order service not calling inventory service directly"; RabbitMQ solves it in a day. Adopting Kafka incurs a month of learning costs for partition planning, consumer group rebalances, and monitoring instrumentation—with zero benefit.

Five Real-World Anti-Patterns

Anti-Pattern 1: Three Services, Yet Choose Kafka

Reason: "Kafka performs well, big companies use it." Result: daily message volume only tens of thousands, but you introduce KRaft cluster, must pre-plan partition count (can only increase, not decrease), rebalances cause consumption pauses, monitoring requires a separate stack. Criterion: If volume hasn't reached 100k/sec and you don't need stream processing, Kafka's throughput advantage is completely unused.

Anti-Pattern 2: Using RabbitMQ for Log Streams

Logs and metrics are high-volume, loss-tolerant, and consumed slowly. RabbitMQ inevitably backs up under these conditions; memory and disk rise simultaneously, and mirror queue synchronization drags down the whole cluster. Criterion: Need long-term retention and replay consumption—that's Kafka's model, not RabbitMQ's.

Anti-Pattern 3: Using Kafka for Delayed Queues

Common hacks: consumer pulls message, sees it's not due, sleeps (wastes consumer threads); or one partition per delay level (partition explosion wastes resources). Correct approach: Delegate delayed scheduling to dedicated tools—RocketMQ scheduled messages, Redis ZSet polling, timing wheel. Kafka only handles "deliver message after the due time."

Anti-Pattern 4: Treating MQ as a Database

No retention policy, no expiration, consumer down for three months unnoticed, disk fills and crashes the cluster. Backlog alerts are mandatory. This matters more than the selection itself—even the best MQ can't survive neglect.

Anti-Pattern 5: Believing Transactional Messages Solve Distributed Transactions

RocketMQ's transactional messages only guarantee atomicity between local transaction and message send. Downstream consumption failures still require compensation. True distributed consistency relies on business compensation, reconciliation, state machines—messaging is just one piece.

Abstraction Layers: What They Can and Cannot Hide

Spring Cloud Stream binders or a custom MessageProducer interface can decouple business code from a specific MQ. But understand the trade-offs:

Can abstract: send/receive model, consumer group concept.

Cannot abstract: delayed messages, transactional messages, partitioning and ordering, routing rules.

The very features that cannot be abstracted are the reasons you selected that MQ in the first place. Conclusion: select by semantics first, then add abstraction layer. Reverse the order and you'll inevitably sacrifice needed semantics for abstraction compatibility.

Beyond the Big Three: Other MQ Options

Pulsar: storage-compute separation, queue + stream dual model, multi-tenancy. Consider for large scale, multi-business sharing, cross-region replication; highest operational complexity.

NATS / JetStream: Go-based lightweight messaging, ultra-low latency. Consider for cloud-native, IoT, high-frequency small messages between services.

Redis Stream: built-in consumer groups and ack. Consider when Redis already exists, volume is small; do not carry core business.

ActiveMQ / Artemis: legacy JMS. Only for maintaining existing systems; new projects need not consider.

Database outbox table: message is just a row in a table. Consider for low volume, strict ordering required, unwilling to introduce new component.

Cloud managed services are worth calculating: the biggest cost of self-hosted MQ isn't servers—it's people . Without dedicated middleware ops, managed services are usually cheaper—trade-off is vendor lock-in, cross-cloud migration difficulty, and peak billing must be estimated upfront.

Checklist

Ask three questions first: can messages be lost, do you need special semantics, who operates it .

Business messages + delayed/transactional → RocketMQ; log streams + replay + stream processing → Kafka; decoupling + routing + lightweight → RabbitMQ.

Backlog capacity matters more than throughput ; RabbitMQ fails first in spike scenarios.

Five anti-patterns: small business on Kafka, log streams on RabbitMQ, Kafka for delayed queues, MQ as database, transactional messages as distributed transaction silver bullet.

Abstraction layers can swap providers, not semantics; select by semantics first, then abstract .

All MQs are at-least-once delivery; idempotency is non-negotiable.

The "MQ in Practice" series concludes here: Kafka intro → RocketMQ intro → message idempotency → selection wrap-up. Together with earlier RabbitMQ articles, mainstream MQ onboarding and selection are covered. Ultimately, the hard parts of MQ aren't "how to send a message" but three questions: will messages be lost, will they be duplicated, did you pick the right one. Get those three clear, and the product choice becomes secondary.

About this article

For questions about attribution, corrections or content rights, please contactadmin@besthub.devand we will review it promptly.

distributed systemsBackend ArchitectureKafkaMessage QueueRabbitMQRocketMQAnti-patternsMQ Selection

Discussion 0

Questions, practical examples and thoughtful responses.

Open full discussion