What is a distributed transaction
The traditional solution based on database local transaction can only guarantee the atomicity, isolation, consistency and persistence of single service processing, but it can't guarantee the consistency of processing among multiple distributed services. Therefore, we must establish a set of coordination mechanism among distributed service processing to ensure the atomicity, isolation, consistency and permanence of distributed service processing.
Why Alipay needs distributed transactions
Based on the SOA architecture, the entire Alipay system is split into a series of independently developed, self-contained, autonomous business services, which are flexibly assembled into the products and solutions needed by the end-user through a variety of mechanisms.
When multiple services collaborate to complete a business, due to business constraints (such as the red envelopes do not meet the use of conditions, account balances, etc.), system failures (such as network or system timeouts or interrupts, database constraints are not satisfied, etc.), can cause the service processing in any step can not continue, so that the data in an inconsistent state, Have serious business consequences, we need a distributed transaction solution to coordinate the business consistency of multiple services.
Alipay's Distributed Transaction framework
Alipay developed a distributed transaction based on a two-phase commit theory (two Phase commit), first giving a logical diagram of phase two submissions: