How Seata’s AT Mode Implements Two-Phase Commit for Distributed Transactions

This article explains Seata’s AT transaction mode, its reliance on the classic two‑phase commit protocol, the roles of TC, TM, and RM, and how snapshot‑based SQL interception ensures consistency and rollback in microservice architectures.

Lobster Programming
Lobster Programming
Lobster Programming
How Seata’s AT Mode Implements Two-Phase Commit for Distributed Transactions

Two-Phase Commit

Two‑Phase Commit (2PC) is a distributed transaction protocol that ensures all participants reach a consistent outcome. In the first, "prepare" phase, the transaction coordinator asks each participant if it can commit; participants respond with "prepared" or "reject" without persisting changes. In the second, "commit" phase, if all participants are prepared, the coordinator sends a commit request, participants persist the changes and acknowledge; otherwise a rollback request is issued.

Advantages of 2PC include simplicity and strong data consistency. Drawbacks are blocking when the coordinator fails, performance overhead due to multiple network round‑trips, and complex failure recovery.

Two-Phase Commit diagram
Two-Phase Commit diagram

Seata AT Mode

Seata’s AT mode introduces three key roles:

TC (Transaction Coordinator) : a standalone component that maintains global transaction state, receives commit/rollback commands from the TM, and coordinates branch transactions.

TM (Transaction Manager) : embedded in the application, it defines the global transaction boundary, generates a unique XID, and instructs the TC to commit or rollback.

RM (Resource Manager) : communicates with the TC, registers branch transactions, reports their status, and executes commit or rollback on the local resource.

These components work together to achieve distributed transaction processing, as illustrated in the architecture diagram below.

Seata AT mode architecture
Seata AT mode architecture

During the first phase, Seata intercepts and parses business SQL, creates a snapshot of the query result, and stores it. The intercepted SQL is then sent through Seata’s JDBC proxy to the actual database, ensuring that the local transaction guarantees data consistency.

In the second phase, the coordinator either deletes the snapshot data and releases row locks on commit, or uses the snapshot to generate reverse SQL for rollback. The DataSourceProxy component provides the necessary JDBC proxy to capture and manage these snapshots.

Original Source

Signed-in readers can open the original source through BestHub's protected redirect.

Sign in to view source
Republication Notice

This article has been distilled and summarized from source material, then republished for learning and reference. If you believe it infringes your rights, please contactadmin@besthub.devand we will review it promptly.

Seata
Lobster Programming
Written by

Lobster Programming

Sharing insights on technical analysis and exchange, making life better through technology.

0 followers
Reader feedback

How this landed with the community

Sign in to like

Rate this article

Was this worth your time?

Sign in to rate
Discussion

0 Comments

Thoughtful readers leave field notes, pushback, and hard-won operational detail here.