Backend Development 39 min read

Distributed Transaction Solutions and Seata: Theory, Configuration, and AT Mode Implementation

This article provides a comprehensive overview of mainstream distributed transaction solutions, explains the CAP theorem and consistency models, compares various approaches such as 2PC, 3PC, TCC, Saga, and demonstrates how to configure and use Seata's AT mode in a micro‑service environment.

Code Ape Tech Column
Code Ape Tech Column
Code Ape Tech Column
Distributed Transaction Solutions and Seata: Theory, Configuration, and AT Mode Implementation

The article introduces the concept of distributed transactions, contrasting monolithic and micro‑service architectures, and explains why remote coordination is required for operations like order creation, inventory deduction, and bank transfers.

It then details the CAP theorem, describing consistency, availability, and partition tolerance, and outlines the three consistency levels—strong, eventual, and weak—highlighting their trade‑offs.

Various distributed transaction solutions are examined, including two‑phase commit (2PC) and three‑phase commit (3PC) with their preparation, commit, and rollback phases, illustrated with flow diagrams and commit / rollback messages.

The article also covers TCC (Try‑Confirm‑Cancel), local message table, MQ‑based reliable message transactions, maximum‑effort notification, and Saga patterns (command‑orchestrated and event‑choreographed), discussing their advantages, disadvantages, and typical use cases.

Seata, an open‑source distributed transaction framework, is introduced with its components (TC, TM, RM) and supported modes (AT, TCC, Saga, XA). The AT mode is explained as a non‑intrusive solution that leverages a two‑phase commit, automatically generating undo logs and row locks.

Step‑by‑step instructions show how to set up the Seata Transaction Coordinator (TC), create required database tables, configure Nacos as the registry and configuration center, push configuration files using a script, and adjust database connection settings.

Client‑side integration is demonstrated by building storage, account, and order services using Spring Cloud Alibaba, MySQL, and OpenFeign. Each service includes the necessary undo_log table, Seata configuration, and business logic wrapped with @Transactional or @GlobalTransactional annotations.

A testing scenario simulates a successful order flow and then forces a timeout in the account service to verify that Seata correctly rolls back the transaction, leaving inventory unchanged.

The article concludes with key take‑aways: matching Seata client and server versions, creating undo_log tables, aligning transaction group names in Nacos, and the overall benefits of Seata’s AT mode for low‑intrusion distributed transactions.

Java2PCseataAT Mode
Code Ape Tech Column
Written by

Code Ape Tech Column

Former Ant Group P8 engineer, pure technologist, sharing full‑stack Java, job interview and career advice through a column. Site: java-family.cn

0 followers
Reader feedback

How this landed with the community

login 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.