Evolution of Distributed Transaction Based on Reliable Message Service

eventual consistency

Eventual consistency refers to the state of the two systems being consistent, either succeeding or both failing. Of course there is 时间限制. In theory, the sooner the better, but in fact, under various abnormal conditions, there may be a certain delay in reaching the final consistent state, but the final state of the two systems is the same.

For this 时间限制, personal understanding:
1. First of all, it is related to the system, and the system does not require high real-time performance.
2. The time is guaranteed to be within the acceptable range, otherwise the user experience will not be good

Evolution of Distributed Transaction Based on Reliable Message Service

image_1c7svg4218g9juvl9e12hadv99.png-25.9kB

process:

1. System A processes tasks
2. After processing, sends messages to message middleware
3. Message persistence
4. Messages are delivered to system B
5. System processes task B

question:

1. If the processing task of system A is completed, the message sending fails
2. The message delivery fails due to network reasons
3. The processing system B fails to process the task

solution:

For problem 1, it is required that the upstream system information must be successfully sent

After the processing task of system A is completed, the information to be sent is recorded locally. A scheduled task constantly checks whether the transmission is successful, and if the transmission is successful, the status modification will be recorded.

image_1c7t0rtvo1hpj1mk7j9t6il18u5m.png-43.3kB

For problem 2, it is necessary to ensure that the message is successfully consumed by the downstream system

If the message is lost during the delivery process, or the acknowledgment response of the message is lost on the way back, the message middleware will re-deliver after waiting for the acknowledgment response timeout until the downstream consumer returns a successful consumption response.

image_1c7t1om0rk4c1s0415ieasb9s23d.png-51.3kB

For problem 3, a retry mechanism for task B is required

When the task processing fails, it returns to the message middleware failure, on the basis of solving the second problem. The message will be sent repeatedly, that is, task B will retry

image_1c7t1umrs18qp1v071a301nkm1lm63q.png-70.6kB

question

1. Due to network problems, the message delivery timed out, and the message mediator retried and sent another message. At this point, the system receives the first message and processes task B. A second message is received and task B is processed. Task B is executed 2 times

2. The processing of task B has always failed, and the message has been retried to send?

For problem 1, the message needs to be idempotent

Before task B processes the message, it first checks whether the message has been consumed. If it is not consumed, task B is successfully processed and the message is recorded. If the message has been consumed, directly return the response success

image_1c7t2kf0s1kk5kphnno1uv01mmd47.png-58.5kB

For problem 2, limit the retry of the task and log the message

The execution of task B keeps failing, indicating that there is a problem with the program, and there is no need to retry. Record the message, (waiting for manual processing, or re-executing the scheduled task)

image_1c7t375071ifo2gitqckuq2nc4k.png-107.3kB

final system

image_1c7t4q1qgs6ku06170bthdg246b.png-59.4kB

Summary: Eventual consistency, mainly in the way of "recording" and "compensation".

Before doing all uncertain things, record things first, then do uncertain things, the result may be: success, failure or uncertainty, "uncertain" (such as timeout, etc.) can be equivalent to failure . If you succeed, you can clean up the recorded things. For failures and uncertainties, you can rely on timed tasks to re-do all the failed things until you succeed.

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=325741308&siteId=291194637