Distributed Transaction Solutions

Three solutions are currently used:
1. Regular school team
2. TCC

Try: try to execute the business
and complete all business checks (consistency)
reserve necessary business resources (quasi-isolation)

Confirm: confirm the execution of the business,
actually execute the business,
do not do any business Check
Only use the business resources reserved in the Try phase
Confirm operation satisfies idempotency

Cancel: cancel the execution of the business
Release the business resources reserved in the Try phase
Cancel operation satisfies idempotency

3. Based on reliable messages
Reliable messages
Realization:

the active party of business activities, In the same local transaction that completes the business processing, record the message data. After the
business processing transaction is submitted, the business passive party is notified through real-time messages, and the message data is deleted after the real-time notification is successful.
The message recovery system regularly finds unsuccessfully sent messages and delivers them to the real-time message Service supplementary sending
Constraint :

The processing result of the passive party does not affect the processing of the active party The message processing operation of the
passive party is an idempotent operation
Cost: The cost

of building a reliable message system The cost of
message data CRUD
Scope of application High sensitivity

to eventual consistency Time
reduction Passive party implementation cost

Implementation method 2:

Before the business transaction is submitted, the business processing requests to send a message to the real-time message service. The real-time message service only records the message data without actually sending it. The
business processing service confirms the sending to the real-time message service after the business transaction is submitted. The real-time message service only sends the message after the confirmation sending instruction is obtained.
After the business transaction is rolled back, the real-time message service cancels the sending.
The message status confirmation system periodically finds the unconfirmed or backtracked message and asks the business processing service for the message. Status, the business processing service determines whether the message is valid according to the message ID or message content.
Cost Two requests are required to send

a message once.
The business processing service needs to implement a message status checkback interface.
Advantages :
independent storage and independent scaling of message data
Reduce the coupling between the business system and the message system


CAP theorem
For a shared data system, only the following three items can be simultaneously Two of:
Consistency: All users see consistent data
Availability: High availability for data updates
Tolerance to Network Partition: In practical terms, partitioning is equivalent to communication time limit requirements. If the system cannot achieve data consistency within the time limit, it means that a partition has occurred, and a choice must be made between C and A for the current operation


Distributed transactions are essentially unified control of the transactions of multiple databases, which can be divided into: no control, partial control and complete control according to the degree of control. No control means not introducing distributed transactions, partial control means two-phase commit of various variants, including the above-mentioned message transaction + eventual consistency, TCC mode, and full control means fully realizing two-phase commit. The advantage of partial control is that the concurrency and performance are very good, but the disadvantage is that the data consistency is weakened, while the complete control sacrifices performance to ensure consistency. The specific method ultimately depends on the business scenario. As a technician, you must not forget that technology serves business, not technology for technology's sake. It is also a very important ability to select technology for different businesses!

Guess you like

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