Distributed Transaction Solutions: 2PC, 3PC, XA, TCC, Saga, Local Message Table, Transactional Messages, and Seata

This article explains the importance of distributed transactions in micro‑service architectures, reviews ACID properties, compares various solutions such as 2PC/3PC, XA, local message tables, transactional messages, TCC, Saga, and introduces the Seata framework with its AT, TCC, and Saga modes, while also discussing consistency versus consensus with Paxos.

Java Architect Essentials
Java Architect Essentials
Java Architect Essentials
Distributed Transaction Solutions: 2PC, 3PC, XA, TCC, Saga, Local Message Table, Transactional Messages, and Seata

In the era of micro‑service architecture, ensuring business consistency across distributed services is critical, making distributed transactions essential.

It begins by recalling the ACID properties of single‑node database transactions and notes that distributed transactions must also satisfy these four guarantees.

The article then outlines the challenges introduced by network communication, which adds a third possible outcome (unknown) and various failure scenarios such as node crashes, message loss, and ordering issues.

Distributed Transaction Solutions

2PC/3PC : Two‑phase commit (2PC) uses a coordinator and participants to ensure all nodes either commit or roll back, but suffers from synchronous blocking, coordinator single‑point failure, and potential data inconsistency. Three‑phase commit (3PC) adds an extra phase and timeout handling but does not fundamentally solve 2PC’s problems.

XA : An extension of 2PC that defines how resources (e.g., MySQL, Oracle) participate in the commit protocol.

Local Message Table : A widely used approach where business operations and message writes are placed in the same local transaction, with a scheduled task polling the table to send messages, ensuring eventual consistency while keeping implementation simple.

Transactional Messages : Leveraging message middleware (e.g., RocketMQ) to decouple business data from message tables; the producer sends a half‑message, performs local work, then confirms the message, with the broker handling retries and rollbacks.

TCC (Try‑Confirm‑Cancel) : An application‑level two‑phase protocol where each operation implements Try, Confirm, and Cancel methods; it offers strong consistency but requires extensive business‑level code and careful handling of failures.

Saga : Breaks a long‑running transaction into a series of local transactions coordinated by a workflow engine; compensating actions are executed in reverse order on failure, providing higher performance at the cost of weaker consistency.

Seata : An Alibaba‑backed open‑source framework offering AT, TCC, Saga, and XA modes. AT intercepts SQL to create before/after images and row locks, providing non‑intrusive transaction management; Seata also supports TCC and Saga with similar principles.

Consistency vs. Consensus : The article compares distributed transaction consistency (atomicity) with Paxos‑based consensus, noting that while both aim for agreement, they operate at different layers; Paxos can help address coordinator single‑point failures in 2PC.

Conclusion : Achieving both high consistency and high performance in distributed transactions is difficult; the recommended practical hierarchy is business avoidance > eventual consistency > strong consistency.

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.

2PCtccConsistencyDistributed TransactionssagaSeata
Java Architect Essentials
Written by

Java Architect Essentials

Committed to sharing quality articles and tutorials to help Java programmers progress from junior to mid-level to senior architect. We curate high-quality learning resources, interview questions, videos, and projects from across the internet to help you systematically improve your Java architecture skills. Follow and reply '1024' to get Java programming resources. Learn together, grow together.

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.