Participant integration modes
A distributed transaction involves two core roles:
Initiator: The application system that starts the distributed transaction.
Participant: The application system that executes the branch transaction. The same application system can act as both an initiator and a participant.
Distributed transactions support three participant integration modes: TCC mode, FMT mode, and Saga mode.
TCC mode
TCC (Try-Confirm-Cancel) is a high-performance distributed transaction integration mode. This mode is highly flexible and supports a wide range of transaction scenarios, such as custom compensating transactions, custom resource reservation transactions, and message transactions. This mode lets you customize the two-phase commit (2PC) protocol to implement specific optimizations and features for your scenarios.
The following figure shows the architecture of TCC mode.
TCC mode has the following features:
Eventual consistency: During transaction processing, data may be temporarily inconsistent. However, the recovery system ensures that the data reaches a consistent state.
Simple protocol: TCC mode defines a standard two-phase interface similar to the 2PC protocol. To use the transaction features of TCC mode, you only need to implement the corresponding interfaces in your business system.
Independent of RPC service protocols: In a Service-Oriented Architecture (SOA), one or more database operations are often packaged as one or more services. These services communicate with each other using RPC protocols. TCC mode is built on the SOA architecture and is independent of the underlying protocol.
Independent of the underlying transaction implementation: TCC is an abstract concept that operates at the service layer and is independent of the underlying transaction implementation. This means that any operation can be part of a TCC transaction, as long as it is wrapped as a TCC participant. This includes operations on relational databases such as MySQL and Oracle, key-value (KV) stores such as MemCache, or column stores such as HBase.
FMT mode
To address the usability issues of TCC mode, Distributed Transaction Service introduced the framework-managed transactions (FMT) mode. FMT is a non-intrusive distributed transaction solution designed for ease of use and quick integration, without requiring modifications to business code.
The following figure shows the architecture of FMT mode.
Saga mode
Saga mode is a long-running transaction solution provided by SEATA. It is suitable for scenarios with long or complex business processes, or where participants include services from other companies or legacy systems. In Saga mode, each participant in a business process commits its local transaction. If a participant fails, the system compensates for the previously successful participants. The forward service in the first phase and the compensation service in the second phase are both implemented by the developer.
The following figure shows the architecture of Saga mode. The left side shows the successful transaction flow. If an exception occurs during the execution of T3, the transaction compensation flow on the right side begins. This flow executes the compensation services for T3, T2, and T1 in reverse order.
Saga mode has the following features:
Commits local database transactions in the first phase, which is lock-free and delivers high performance.
Participants can use transaction-driven asynchronous execution for high concurrency and high throughput.
The compensation service is the inverse of the forward service, which makes it easy to understand and implement.
It supports service orchestration, visual design, and execution trace monitoring.