This is the second day of my participation in Gwen Challenge
Summary of MQ
MQ, short for Message Queue, is a container that stores messages during transmission and is used for communication between distributed systems.
Graph TD A system --> MQ-->B system
System A produces messages and System B consumes messages MQ message middleware
The pros and cons of MQ
advantage
- The application of decoupling
- Asynchronous speed
- Peak peel
disadvantage
- The system availability decreases
- System complexity enhancement
- Consistency problem
The application of decoupling
Graph TD Order System --> Logistics System Order System --> Inventory System Order System --> Payment System
The user clicks the button to place an order to access the order system, which asks the inventory system to reduce inventory, the payment system to pay, and the logistics system to deliver goods. Directly go through the remote call to notify the three systems, then the four systems are coupled together, can appear some problems, such as inventory system appear problem, the whole process is likely to appear problem, the customer through the order system to place the order, are likely to get an order failure feedback, system fault tolerance is low. For example, when a new requirement requires access to the shopping cart system when placing an order, the order system code has to be modified, which reduces maintainability. How do you solve this problem with MQ
Graph TD Order System --> MQ MQ --> Logistics system MQ --> Inventory System MQ --> Payment system
The user places an order and visits the order system, the order system sends a message to Mq, at which point we can notify the order system that the order was successful, and the downstream system can get the message from Mq and consume it. The system is more fault tolerant. When you add another system, you just need the new system to get the message and consume it at MQ.
Asynchronous speed
Originally, it used to process the operation after placing an order through remote call. When one system was finished, it returned to the next system. It took 200ms to call one system and nearly 600ms to call three systems, not counting the processing time of order system itself, so the user experience was very poor. In contrast, using MQ, we only need to send the message to MQ to return the display of order completion, and other processing systems get the message and consume by themselves. The storage of the storage, the delivery of express delivery, the whole process will not take more than 100ms, improving efficiency, improving system throughput, and excellent user experience.
Peak peel
Or mall system, Dragon Boat Festival mall activities 0.1 seconds to kill moon cakes, without MQ, the order system can handle the maximum traffic per second 1000, the activity began, 50000 people began to order, request all sent over, order system instantly hung, cool.
Graph TD user A --> Order system user B --> Order system user C --> Order system user 3-5000 --> Order system user
When using the mq, mq throughput is very big, we can use the mq, let all the requests are sent to mq, cached, ordering system use part of the continuing to mq inside take message, received a large number of requests and result in order to avoid the system hang up, reduced the peak flow, exist in the mq message slowly consumed, fill in the valley.
Graph TD user A --> MQ user B --> MQ user C --> MQ user 3-50000 --> MQ MQ --> Order system
The system availability decreases
With the introduction of MQ, previously we just needed to keep the systems running flawlessly. Now we need to keep MQ running flawlessly. The more external dependencies we introduce, the more unstable the system becomes and the less available it becomes.
System complexity enhancement
Before it was called directly, now through MQ, it adds complexity to the system, how to ensure that messages are not repeatedly consumed, messages are lost, the order in which they are delivered.
Consistency problem
A sends A message to the BCD system for processing, BC processing is complete, D system hangs up, the message is inconsistent.
summary
Mq has advantages and disadvantages, so how do we decide to use MQ
- The sender of the message does not need to get feedback from the receiver in order for the producer to be nearly done before the consumer is done.
- Allow for temporary inconsistencies, but eventually there will be consistency.
- Beneficial to the system potential, that is, the benefits outweigh the disadvantages, decoupling, performance improvement, peak cutting and valley filling.