How Seata‑Golang Enables Distributed Transactions in Go Microservices

This article introduces Seata, a high‑performance open‑source distributed transaction solution, explains the Seata‑Golang 1.0.0 release and its demo at a Go meetup, details the core AT‑mode architecture, describes the MySQL driver that integrates Seata‑Golang, and outlines future plans for broader database support.

Alibaba Cloud Native
Alibaba Cloud Native
Alibaba Cloud Native
How Seata‑Golang Enables Distributed Transactions in Go Microservices

Seata Overview

Seata is a simple, high‑performance, open‑source, one‑stop solution for distributed transactions. Since its open‑source launch in January 2019, it has been adopted by hundreds of enterprises in production environments.

Seata‑Golang Release and Meetup Demo

In April 2020 the team began developing a multi‑language Go implementation of Seata. After a year of work, Seata‑Golang 1.0.0 was released. On April 17 this year, the project was presented at the Chengdu Gopher meetup, where a live demo showed how to integrate Seata‑Golang into microservices to ensure data consistency across services.

Seata AT‑Mode Architecture

The demo illustrated the AT‑mode workflow, which involves the following components:

TC (Transaction Coordinator) : the distributed transaction coordinator.

TM (Transaction Manager) : manages global transactions, handling start, commit, and rollback.

RM (Resource Manager) : manages branch transaction resources and reports execution status to the TC.

XID : a globally unique identifier for a GlobalSession created by the TM.

BranchID : a globally unique identifier for a BranchSession generated by the TC when an RM registers a branch transaction.

If an RM reports a branch failure, the TC marks the BranchSession as failed. When the TM initiates a rollback, the TC uses the XID to locate all successful branch transactions and instructs them to roll back.

MySQL Driver Integration

A new MySQL driver, built on go-sql-driver/mysql v1.5.0, embeds Seata‑Golang’s distributed transaction capabilities. It fully supports the database/sql abstraction, allowing seamless integration with ORM frameworks that rely on this layer.

During a Commit or Rollback, the driver checks whether the connection context ( connCtx) is present. If present, it packages the undo log with business data and reports the branch status to the TC; otherwise, it performs a normal commit or rollback.

The undo log is serialized as JSON. For example, changing a row from name='TXC' to name='GTS' generates an undo log that can produce a compensating SQL statement like UPDATE product SET name='TXC' WHERE id=1. Insert operations generate delete statements, and delete operations generate insert statements.

Future Plans

The community has already integrated the MySQL driver with GORM and deployed Seata‑Golang in production. Currently, Seata‑Golang only supports MySQL; future work includes creating drivers for PostgreSQL and Oracle based on the existing MySQL driver design.

With the rise of Go microservice development, distributed transaction challenges are gaining attention. The authors invite more community participation to enhance the framework, sustain its vitality, and create value.

References

Seata official site: https://seata.io

Java version of Seata: https://github.com/seata/seata

Seata‑Golang project: https://github.com/opentrx/seata-golang

MySQL driver: https://github.com/opentrx/mysql

Bilibili talk: https://www.bilibili.com/video/BV1oz411e72T

Communication model details: http://seata.io/zh-cn/blog/seata-golang-communication-mode.html

Seata architecture diagram
Seata architecture diagram
AT mode workflow
AT mode workflow
Future roadmap
Future roadmap
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.

BackendmicroservicesGodistributed transactionsSeataMySQL driver
Alibaba Cloud Native
Written by

Alibaba Cloud Native

We publish cloud-native tech news, curate in-depth content, host regular events and live streams, and share Alibaba product and user case studies. Join us to explore and share the cloud-native insights you need.

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.