Interview Guide: Why Use Message Queues, Their Pros and Cons, and Comparison of Kafka, ActiveMQ, RabbitMQ, and RocketMQ
This article explains why message queues are used in system architecture, outlines their advantages such as decoupling, asynchronous processing, and traffic shaping, discusses their drawbacks, and compares four popular MQ solutions—Kafka, ActiveMQ, RabbitMQ, and RocketMQ—to help candidates ace interview questions.
Preface
The author intends to strengthen technical knowledge for upcoming job interviews, focusing on Redis and Message Queues (MQ) as solutions for server concurrency problems.
Interview Question Introduction
Why use MQ?
What are the advantages and disadvantages of message queues?
Differences among Kafka, ActiveMQ, RabbitMQ, and RocketMQ.
Interviewer Psychology Analysis
1. Why does your system use MQ? Interviewers want to see if you understand the business scenario and technical challenges that justify MQ adoption.
2. Do you know the pros and cons of MQ? Blindly using MQ without understanding its trade‑offs suggests a lack of critical thinking.
3. Did you research the specific MQ you chose? Selecting the right MQ requires evaluating strengths and weaknesses relative to the system’s needs.
Question Breakdown
① Why Use MQ
Common use cases include system decoupling, asynchronous processing, and traffic shaping.
System Decoupling
When multiple services depend on a single provider, a failure in one consumer can crash the provider. By publishing messages to an MQ, producers no longer need to know which consumers exist, reducing tight coupling.
Consumers simply pull messages from the queue, and can stop consuming without affecting the producer.
Asynchronous Calls
Without MQ, a request may need to wait for multiple downstream services, leading to response times near one second. With MQ, the producer sends messages quickly (e.g., 5 ms) and returns, while downstream services process asynchronously, reducing user‑perceived latency to under 10 ms.
Traffic Shaping (Peak‑Cutting)
During high‑traffic events (e.g., a mask‑sale with millions of concurrent requests), MQ can absorb bursts by queuing requests and processing them at a sustainable rate, preventing system crashes while tolerating temporary latency.
Advantages of Message Queues
Decoupling, asynchronous processing, and traffic shaping are the primary benefits.
Disadvantages of Message Queues
1. Reduced System Availability: Introducing an external dependency (the MQ) creates a single point of failure.
2. Increased Complexity: Issues such as duplicate consumption, message loss, and ordering must be handled.
3. Consistency Challenges: A request may appear successful after being placed on the queue, but downstream services might fail, leading to data inconsistency.
Comparison of Four Mainstream MQs
The industry’s four major MQs are Kafka, ActiveMQ, RabbitMQ, and RocketMQ. A summary table (image) illustrates their strengths and weaknesses.
Recommendations
Small‑to‑medium companies with modest technical strength should choose RabbitMQ.
Large enterprises with strong infrastructure teams may opt for RocketMQ.
Big‑data or real‑time log‑processing scenarios are best served by Kafka.
Overall, while MQ brings powerful capabilities, it also raises architectural complexity that must be carefully managed.
Top Architect
Top Architect focuses on sharing practical architecture knowledge, covering enterprise, system, website, large‑scale distributed, and high‑availability architectures, plus architecture adjustments using internet technologies. We welcome idea‑driven, sharing‑oriented architects to exchange and learn together.
How this landed with the community
Was this worth your time?
0 Comments
Thoughtful readers leave field notes, pushback, and hard-won operational detail here.