The simplest solution to a distributed transaction is forward or backward, that is, supplement or rollback.

The business logic has the following three steps:

  1. Call service A to freeze the amount
  2. Call the B service to increase the quota
  3. Record database

Step 2 failed -> Write task, rollback step 1 (notify A server to rollback)

Step 3 fails -> Write task to synchronize data from A/B service to database

Another option is to write A task, convert it to A local transaction, and let the task perform the above three steps, and retry the task if it fails. Of course, A/B services have idempotent processing. One of the disadvantages of this scenario is that it assumes that the service will eventually succeed if the parameters are reasonable, and another is that it seems unnatural.

The complex scheme is the TCC scheme, see ANT Financial’s DTS