1 – why do you need message queues

Time:2021-7-27

Why message queuing

Asynchronous processing: suppose an interface has three ABC operations, operation a can be completed quickly, but the BC operation is time-consuming. At this time, the BC operations can be put into the message queue and returned directly, so as to reduce the waiting time of the interface.

flow control: suppose that our database system can only process 2K requests per second. Under normal conditions, the number of concurrent requests per second is 50. During the peak period, the system needs to process 5K requests per second. If these 5K requests directly access the database, the database must not be able to carry them. If MQ is used, 5K requests are written to MQ every second, and then the system slowly pulls requests through MQ, pulling 2K requests every second. During the peak period, a large number of requests are overstocked in MQ, but after the peak period, 50 requests enter MQ every second, and the system pulls 2K requests from MQ every second, and the system can quickly consume the overstocked messages.

Service decoupling: take the insurance company as an example. After the case in system a is closed:

  • System B needs to upload the compensation information of the case to the supervision platform

  • System C needs to conduct risk analysis on this case and identify whether it is a case of insurance fraud or a case requiring recovery

The traditional approach is: system a calls the interfaces of Systems B and C respectively. Assuming that there are systems D, e and f that also need to know whether the case is closed, system a also needs to modify the code.

After introducing the message queue, system a will send a closing message directly to the message queue after the case is closed. All downstream systems only need to subscribe to this message. Whether the downstream systems are added or reduced, system a does not need to modify the code.

Data distribution

Summary

Message queuing also has its own problems and limitations, including:

The delay problem caused by the introduction of message queue;

It increases the complexity of the system;

Data inconsistency may occur.

This work adoptsCC agreement, reprint must indicate the author and the link to this article