Comprehensive Guide to Seata Distributed Transaction Framework
This article provides an in‑depth overview of Seata, an open‑source distributed transaction solution, covering its core components, workflow, and the four transaction modes (AT, TCC, SAGA, XA) along with their characteristics and usage in microservice architectures.
Seata is an open‑source distributed transaction solution from Alibaba, designed for microservice architectures to provide high‑performance, easy‑to‑use transaction services.
Seata Core Components
Seata transaction management consists of three key roles: Transaction Coordinator (TC), Transaction Manager (TM), and Resource Manager (RM). TC maintains global and branch transaction states and coordinates commit or rollback. TM defines the scope of a global transaction, starts it, and triggers commit or rollback. RM manages branch resources, registers branch transactions with TC, reports status, and drives branch commit or rollback.
Seata Workflow
A typical Seata distributed transaction proceeds as follows: (1) TM requests a global transaction from TC and receives a global XID; (2) the XID propagates through RPC calls; (3) each RM obtains the XID and registers a branch transaction with TC, receiving a branch XID; (4) RM executes local business logic, commits the branch, and reports status to TC; (5) after the call chain finishes, TM decides to commit or roll back the global transaction via TC.
Seata Transaction Modes
Seata supports four transaction modes: AT, TCC, SAGA, and XA, offering a one‑stop solution for distributed transactions.
1. AT Mode
AT mode is the default and works with relational databases that support ACID. It provides eventual consistency without business code intrusion. In the first phase, business data and rollback logs are written together; in the second phase, the commit succeeds immediately and rollback logs are cleaned up asynchronously. Rollback uses the logs to generate compensating operations.
First‑phase prepare: commit business data and write rollback log in the same local transaction.
Second‑phase commit: automatically and asynchronously clean up rollback logs.
Second‑phase rollback: automatically generate compensating actions from the rollback log.
2. TCC Mode
TCC (Try‑Confirm‑Cancel) allows custom branch transactions to be managed in a two‑phase commit model. Each branch must implement its own prepare, commit, and rollback logic. The first phase invokes the custom prepare method; the second phase invokes either the custom commit or custom rollback method based on the global outcome.
3. SAGA Mode
In SAGA mode, each participant commits a local transaction. If any participant fails, compensating actions are executed for all previously successful participants. Both the forward service and the compensation service are implemented by the business code.
4. XA Mode
XA is a standard two‑phase commit protocol that provides strong consistency at the cost of some availability. It requires XA‑capable resources (e.g., databases) and Java/JDBC access. Seata simplifies XA usage by handling the coordination while the underlying resource manager implements the XA interface.
Comparison of the Four Modes
Mike Chen's Internet Architecture
Over ten years of BAT architecture experience, shared generously!
How this landed with the community
Was this worth your time?
0 Comments
Thoughtful readers leave field notes, pushback, and hard-won operational detail here.