Simple processing of distributed transactions

The simplest solution to a distributed transaction is to go forward or backward, that is, replenish or roll back.

The business logic has the following three steps:

  1. Call service A to freeze the amount

  2. Call B service to increase the quota

  3. record database

Failed to go to step 2 -> write task, roll back step 1 (notify service A to roll back)

Proceed to step 3 and fail -> write task, synchronize data from A/B service to database

Another solution is to write a task, convert it into a local transaction, and let the task perform the above three steps. If it fails, retry the task. Of course, A/B services have idempotent processing. One of the disadvantages of this scheme is that the service will eventually be executed successfully under the assumption that the parameters are reasonable. The second disadvantage is that it looks unnatural.

The complex solution is the TCC solution, see Ant Financial's DTS

Guess you like

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