Why use a message queue?

Interview questions

  • Why use a message queue?
  • Message Queuing what advantages and disadvantages?
  • Kafka, ActiveMQ, RabbitMQ, RocketMQ what's the difference, and what scenarios fit?

Interviewer psychological analysis

In fact, the interviewer mainly want to see:

  • First : Why do you use this technique?
    Many interviewers Why use this technology for lack of thinking, but only for use with, and not have their own independent thinking, the concept for architecture design nor global.
  • Second : Is it clear to you the pros and cons of this technology?
    Whether for deep thinking skills, understand the pros and cons of the introduction of new technology brings. If not, just the code handling tools, the lack of independent thinking.
  • Third : Selection of the technical considerations?
    MQ products on the market mature a lot, no one is absolutely perfect, we have not considered the issue of technology selection.

Analysis of interview questions

Why use a message queue?

In fact, just I want to know what the reason is because the MQ technology introduced, in order to solve what problems. Interviewer is looking to answer is, did your company have what kind of business scenario, this scenario what kind of technical challenges, there may be trouble without MQ, MQ introduced now brings the benefits.
By MQ benefits are: decoupling, asynchronous, clipping .

Decoupling

This scenario usually publish subscribe model, for example: System A system to give B, C, D to send messages. If this time adding a new system E, you need to change the code system A can send a message to the system E, if you are using MQ, producers and consumers can be decoupled.
Summary : through a MQ, to achieve Pub / Sub publish subscribe model such a model, to achieve a decoupling.
Interview Tips : You need to consider whether there is a similar scene own system is a module called a number of other modules, to maintain a lot of trouble with each other. But the call actually does not require synchronous calls. If you are using MQ asynchronous decoupling, it is also possible. It is reflected in your resume, using MQ decoupling.

asynchronous

If A receives a request to write its own local library requires 100ms, while the B to call the system takes 200ms, the system cost C 100ms, System D cost 300ms. The total time-consuming compared to 700ms, which in the Internet project can be tolerated. MQ will use asynchronous call, then A system like this is almost just 100ms can be returned.

Clipping

QPS system usually about 50 or so, but when faced with an emergency situation, QPS soared to 5000, if the data request system is directly based on MySQL, then MySQL may crash. General MySQL's TPS in about 2K. Instantaneous peak avalanche may cause the system to appear.
If the MQ, the peak time to write data to MQ, according to their end consumer can afford to spend to, not because the request excessive pressure cause a crash. Then the system is idle time, to squeeze consumed data.
The short squeeze is allowed, because when the peak of the past, the system will quickly consumed squeeze data.

Message Queue What are the disadvantages?

Advantages have already said, there are corresponding benefits in Special Scenes: decoupling, asynchronous, clipping.
The main drawback of the following three:

  • Reducing system availability:
    introducing external dependencies, the more low availability. Direct calls, so long as there is no system failure will not go wrong. But once introduced MQ, we need to consider MQ usability problems.
  • Enhance the complexity of the system:
    the system adds a MQ came in, issues to be considered will become more, you need to consider how to ensure the situation does not repeat consumption (idempotency), how to handle the case of message loss (reliability), how assure an orderly messaging (sequential).
  • Consistency:
    If A system processed directly back to success, BCD system in case there are errors, then appeared inconsistent data situation, how to deal with?

So the message queue is a very complex architecture, introduced it will bring some benefits, but if for no consideration everywhere, but there will be a series of problems. However, in some scenarios, the use or want to use, how to avoid the need to clear out the risk.

Kafka, ActiveMQ, RabbitMQ, RocketMQ what advantages and disadvantages?

characteristic ActiveMQ RabbitMQ RocketMQ Kafka
Stand-alone Throughput Ten thousand, lower than RocketMQ, Kafka an order of magnitude With ActiveMQ 100,000 level, supporting high throughput 100,000, high throughput, large data classes with the general system for real-time calculation data, the log collection and other scenes
The number of topic on the impact on throughput topic can reach hundreds / thousands of levels, throughput will decrease to a lesser extent, this is RocketMQ a big advantage, in the same machine, can support a large number of topic topic from tens to hundreds of times, throughput could drop significantly, the use of Kafka topic to ensure that not too much
Timeliness ms level Microsecond, which is a major feature of RabbitMQ, lowest latency ms level Within delay in ms
Availability High, based on a master-slave architecture With ActiveMQ Very high, distributed architecture Very high, distributed architecture, a node goes down will not affect other nodes
Message reliability There is little probability of loss Basic is not lost 0 loss can be configured to do With RocketMQ
Support functions MQ function and complete field Based on the development of erlang, concurrency is very strong, excellent performance, low latency MQ function more perfect, or a distributed architecture, scalability Function is relatively simple, the main support simple MQ function, real-time computing, and log data collected in the field is large scale use

After the summary, various comparison, has the following recommendations:
SMEs recommends using RabbitMQ, rich management interface out of the box, good stability.
There are self-development capacity of enterprises, can use RocketMQ, supporting high throughput.
There are big data-related business, it can be used directly Kafka, Kafka, after all, in the field of big data is already a de facto standard.

Released six original articles · won praise 0 · Views 28

Guess you like

Origin blog.csdn.net/qq_26375325/article/details/105081172