Distributed system data consistency




There are two solutions to distributed transaction data consistency in distributed systems :
1. Asynchronous message (message queue)
(1) Using asynchronous message Consumer needs to implement idempotency, which means that multiple requests return the same result.
(a) One way is that the business logic guarantees idempotency. For example, after receiving a payment successful message, the order status becomes payment completed. If the current status is payment completed, then receiving another payment successful message indicates that the message is repeated, and it is directly processed as a message successfully.
(b) Another way is to add a deduplication table or a similar implementation if the business logic cannot guarantee idempotency. For the producer side, put a message library on the same instance of the business database, and send messages and business operations in the same local transaction. When sending a message, the message is not sent immediately, but a message record is inserted into the message database, and then the message is sent asynchronously when the transaction is submitted. If the message is sent successfully, the message in the message database is deleted. If the message queue is encountered Service exception or network problem, the message is not sent successfully, then the message is left here, and another service will continuously sweep these messages out and resend them.

2. Some businesses are not suitable for asynchronous messages, and each participant of the transaction needs to obtain the result synchronously . A transaction record library is placed on the same instance of each participant's local business library. A central service compares the transaction record tables of the three parties to make a final decision. Suppose that the current transaction record of the three parties is that A succeeds, B fails, and C succeeds. Then the final decision has two ways, according to the specific scenario:
(1) Retry B until B is successful, and the transaction record table records various call parameters and other information;
(2) Execute the compensation operation of A and B (a feasible The compensation method is rollback).


DTS scheme
1. Alipay is improved on the basis of 2PC.
2. Distributed Transaction Service (DTS) is a distributed transaction framework to ensure the eventual consistency of transactions in a large-scale distributed environment.


In a distributed environment (data distribution), it is impossible to ensure data consistency at any time, and only a compromise solution can be adopted to ensure the final consistency of data.



Refer to the original text (6 solutions to ensure data consistency in distributed systems): http://www.cnblogs.com/lzyGod/p/5558474.html
Refer to the original text (about data consistency in distributed systems): http:/ /elf8848.iteye.com/blog/2067771


Guess you like

Origin http://10.200.1.11:23101/article/api/json?id=326713094&siteId=291194637