Backend Development 11 min read

Seata Distributed Transaction Framework: Concepts, Architecture, and Spring Boot Demo

This article introduces the open‑source Seata distributed transaction solution, explains its AT, TCC, SAGA and XA modes, describes the TC‑TM‑RM components and workflow, and provides a step‑by‑step Spring Boot demo with Docker, Maven dependencies, configuration, and code examples for a multi‑service purchase scenario.

Full-Stack Internet Architecture
Full-Stack Internet Architecture
Full-Stack Internet Architecture
Seata Distributed Transaction Framework: Concepts, Architecture, and Spring Boot Demo

Spring Boot is a popular microservice framework, and this guide presents a comprehensive tutorial for quickly integrating common middleware, focusing on the open‑source distributed transaction framework Seata.

Seata offers four transaction modes—AT, TCC, SAGA, and XA—providing a one‑stop solution for high‑performance, easy‑to‑use distributed transactions. Its advantages include non‑intrusive business integration and reduced performance overhead.

AT mode works in two phases: the first phase records business data and rollback logs in a local transaction; the second phase asynchronously commits and cleans up logs, using the logs to generate compensation operations if a global rollback is required.

TCC mode defines custom prepare, commit, and rollback logic for each branch transaction, allowing the global transaction manager to control them without relying on underlying resource transaction support.

The framework consists of three core components: the Transaction Coordinator (TC) that maintains global and branch transaction states, the Transaction Manager (TM) that defines transaction boundaries, and the Resource Manager (RM) that registers branch resources and drives commit/rollback.

The overall transaction flow is: TM requests a global transaction from TC, generating a unique XID; the XID propagates through the microservice call chain; RM registers branch transactions with TC; TM issues a global commit or rollback decision; TC coordinates all branches to complete the request.

Demo Setup

Use Docker to run a Seata server:

docker pull seataio/seata-server
docker run --name seata-server -p 8091:8091 seataio/seata-server

The demo models a purchase scenario with three microservices: storage (inventory), order (order creation), and account (balance deduction). Each service is a separate Spring Boot project with its own database.

Add the Seata starter dependency to the Maven pom:

<dependency>
    <groupId>io.seata</groupId>
    <artifactId>seata-spring-boot-starter</artifactId>
    <version>1.0.0</version>
</dependency>

Configure each service’s application.properties with its datasource and Seata group settings, e.g.:

spring.application.name=spring-boot-bulking-seata-account
server.port=8081
spring.datasource.url=jdbc:mysql://127.0.0.1:3306/db_seata_1?useSSL=false&serverTimezone=UTC
spring.datasource.username=root
spring.datasource.password=111111
seata.tx-service-group=my_test_tx_group
seata.service.grouplist=127.0.0.1:8091

Business logic is annotated with @GlobalTransactional to start a global transaction, for example:

@GlobalTransactional
public void purchase(String userId, String commodityCode, int orderCount) {
    storageClient.deduct(commodityCode, orderCount);
    orderClient.create(userId, commodityCode, orderCount);
}

To propagate the XID across HTTP calls, a ClientHttpRequestInterceptor reads the XID from RootContext and adds it to the request header.

@Component
public class RestTemplateInterceptor implements ClientHttpRequestInterceptor {
    @Override
    public ClientHttpResponse intercept(HttpRequest request, byte[] body, ClientHttpRequestExecution execution) throws IOException {
        HttpRequestWrapper wrapper = new HttpRequestWrapper(request);
        String xid = RootContext.getXID();
        if (StringUtils.isNotEmpty(xid)) {
            wrapper.getHeaders().add(RootContext.KEY_XID, xid);
        }
        return execution.execute(wrapper, body);
    }
}

Testing shows that Seata deletes records from the undo_log table after a transaction completes, and you can observe data changes by setting breakpoints in the order service.

All source code is available at:

https://github.com/aalansehaiyang/spring-boot-bulking

Seata’s main distinction from other distributed transaction solutions is that it commits branch transactions in the first phase, assuming most business operations succeed, which reduces lock holding time and improves overall efficiency.

DockermicroservicesSpring BoottccDistributed TransactionsseataAT Mode
Full-Stack Internet Architecture
Written by

Full-Stack Internet Architecture

Introducing full-stack Internet architecture technologies centered on Java

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.