DTM Distributed Transaction Manager

repository·main·Indexed 27 days ago

https://github.com/dtm-labs/dtm

A distributed transaction framework that ensures eventual data consistency across microservices. DTM supports multiple transaction patterns including SAGA, TCC, XA, Workflow, and Two-Phase Messages. It provides SDKs for Go, Java, PHP, C#, Python, and Nodejs, and integrates with storage engines such as MySQL/MariaDB, Redis, BoltDB, and MongoDB. The framework includes a Go-based server, Helm charts for Kubernetes deployment, and clients like dtmcli and dtmgrpc for interacting with transaction patterns.

Tokens
3.6K
Snippets
7
Records
26
Agent score
95%

What's inside DTM

  1. Overview of DTM Distributed Transactions Manager

    main

    DTM is a distributed transaction framework designed to provide eventual data consistency across multiple services. It supports several transaction patterns including:

    • SAGA: For long-running transactions with compensating actions.
    • TCC (Try-Confirm-Cancel): For high-consistency requirements.
    • XA: For distributed transactions following the XA standard.
    • Workflow: For complex, multi-step transaction orchestration.
    • Outbox / 2-phase messages: For reliable event publishing and subscription.

    DTM supports multiple languages (Go, Java, PHP, C#, Python, Nodejs) and various storage engines such as MySQL/MariaDB, Redis, BoltDB, and MongoDB.

  2. DTM Features and Supported Modes

    main

    DTM is a cross-language distributed transaction manager supporting various patterns and environments:

    Transaction Modes:

    • SAGA: For long-running transactions with compensation logic.
    • TCC: Try-Confirm-Cancel.
    • XA: For strong consistency (recommended over AT mode).
    • Two-Phase Message: For eventual consistency.

    Supported Languages (SDKs):

    • Go, Java, PHP, C#, Python, Nodejs

    Supported Storage Engines:

    • MySQL (Commonly used)
    • Redis (High performance)
    • MongoDB (Planned)

    Supported Microservice Frameworks:

    • go-zero, go-kratos/kratos, polarismesh/polaris
  3. Handle sub-transaction failures in SAGA

    main
    In a SAGA transaction, if a sub-transaction's forward action fails, DTM will trigger the compensation (rollback) actions for all previously successful sub-transactions. To signal a failure that should trigger an immediate rollback without further retries, return a non-2xx status code (e.g., 409) from your microservice endpoint.
  4. Run DTM locally

    main

    To run the DTM server from the source repository, clone the repository and use the Go toolchain to run the main entry point.

    git clone https://github.com/dtm-labs/dtm && cd dtm
    go run main.go
  5. Use the Workflow client for mixed transaction patterns

    main

    The workflow package is a flexible Go client for DTM. It supports mixing transaction patterns such as saga, tcc, and xa, and allows for mixed usage of http, grpc, and local transactions. This pattern is highly recommended for transactions that require rollback capabilities.

    For implementation details, refer to the following quick start guides:

  6. Install, upgrade, or uninstall DTM via Helm

    main
    You can manage the DTM deployment using Helm charts. Use the following commands to install a new instance, upgrade an existing one, or remove the deployment from your Kubernetes cluster.
  7. Run a Quick Start Workflow example

    main

    To see a working example of an inter-bank transfer using a gRPC workflow, clone the quick-start sample repository and run the workflow-grpc example.

    git clone https://github.com/dtm-labs/quick-start-sample.git && cd quick-start-sample/workflow-grpc
    go run main.go
  8. Run the DTM server

    main
    The DTM server is the central entrypoint for managing distributed transactions. It is initialized via the entry.Main function, which handles configuration and application startup. The server supports graceful shutdown via SIGINT and SIGTERM signals.
  9. Run a SAGA distributed transaction example

    main

    To see a working example of a SAGA transaction (simulating a cross-bank transfer with TransOut and TransIn branches), use the provided Go sample repository.

    git clone https://github.com/dtm-labs/dtmcli-go-sample && cd dtmcli-go-sample
    go run main.go