1 Seata architecture

Seata currently supports four distributed solutions, and there are many similarities in the overall architecture. Here’s an overview of the solutions, and see the related blogs for details on each solution.

1.1 Overall Architecture



Note: This figure is from seATA website

  • Transaction Coordinator (TC) : Maintains the status of global and branch transactions and drives the submission or rollback of global transactions.
  • TM (Transaction Manager) Transaction Manager: Defines the scope of a global Transaction: start, commit, or roll back a global Transaction.
  • Resource Manager (RM) : Manages the resources for branch transaction processing, communicates with TCS to register branch transactions, report the status of branch transactions, and drive the submission or rollback of branch transactions.

Now look AT the differences between AT, TCC, XA and Saga.

1.2 Seata – the AT



Note: This figure is from seATA website.

Seata – AT mode

1.3 Seata – TCC

Note: This figure is from seATA website. Seata – TCC mode

1.4 Seata – Saga

Seata – Saga mode

1.5 Seata – XA



Note: This figure is from seATA website.

Seata – XA mode

2 Introduction to Source Code

See seATA for the source of seATa-server. If you want to explore the source code, start with the following classes:

2.1 Global Transaction start portal

  • GlobalTransactionalInterceptor: Global transaction interceptor, TM in a Global transaction by such open, and conducted by such notice TC Global Commit/Rollback. Mainly refer to the following methods:

    • public Object invoke(final MethodInvocation methodInvocation) throws Throwable; Responsible for starting, committing and rolling back distributed transactions.
  • StateMachineInstance: saga distributed transaction StateMachineInstance, used to manage saga distributed transactions.

2.2 Entry for RM Request Processing

  • AbstractRMHandler: Main entry for the RM to accept TC requests.

    • public BranchCommitResponse handle(BranchCommitRequest request) ; Process branch commit requests.
    • public BranchRollbackResponse handle(BranchRollbackRequest request) ; Handle branch rollback requests.

2.3 Entry for TC Request Processing

  • AbstractTCInboundHandler: main entry for TCS to process TM and RM requests.

    • public GlobalBeginResponse handle(GlobalBeginRequest request, final RpcContext rpcContext) ; Process the TM begin request.
    • public GlobalCommitResponse handle(GlobalCommitRequest request, final RpcContext rpcContext) ; Accept TM’s global transaction submission request.
    • public GlobalRollbackResponse handle(GlobalRollbackRequest request, final RpcContext rpcContext) ; The global transaction rollback request for TM is processed
    • public BranchRegisterResponse handle(BranchRegisterRequest request, final RpcContext rpcContext) ; Handle RM’s request to register branch transactions
    • public BranchReportResponse handle(BranchReportRequest request, final RpcContext rpcContext); In Saga transaction mode, state reports branch transaction information to TC through this method.
    • Public GlobalReportResponse Handle (GlobalReportRequest Request, Final RpcContext RpcContext) State uses this method to report global transaction information to TC.

2.4 compensation

A DefaultCoordinator has several scheduled tasks that can be used to retry or compensate for failures. These tasks can ensure the accuracy of global transactions even if the process fails or the system is forcibly shut down.

  • RetryRollbacking: attempts to Rollback Global Rollback after the Rollback fails.
  • Retryresearch: After the Commit fails, try to recommit globally.
  • Asyncresearch: Similar to retryresearch (do), but do an asynchronous Global Commit.
  • TimeoutCheck: Checks whether a global transaction has timed out.
  • UndoLogDelete: deletes the undo log asynchronously.

3 Reference Documents

Seata AT mode

Seata XA mode.

Seata Saga mode

Seata TCC mode

How are distributed transactions implemented? Read Seata’s XA schema in depth

Distributed transaction Seata and its three modes, rounding | Meetup# 3 review

TCC for flexible transaction solutions

Principle of Seata

Seata – AT mode

Seata – TCC mode

Seata – Saga mode

Seata – XA mode

TCC ws-transaction principle