dtm
A distributed transaction framework, supports workflow, saga, tcc, xa, 2-phase message, outbox patterns, supports many languages.
DTM is an open-source Go framework for managing distributed transactions across multiple services or databases, ensuring operations either all succeed or all roll back, with SDKs for Go, Java, Python, Node.js, PHP, and C#.
DTM is a framework for managing distributed transactions, which are operations that span multiple separate services or databases and need to either all succeed or all be undone together. In a typical modern application, different parts of the system run as independent services. When a user action touches several of those services (for example, deducting money from one account and crediting another), keeping all of them in sync when something goes wrong is genuinely hard. DTM exists to solve that problem.
The framework supports several well-established patterns for handling this coordination. SAGA breaks the overall transaction into a series of steps, each with a corresponding undo step if something fails. TCC (Try, Confirm, Cancel) reserves resources first before committing. XA is a classic two-phase commit standard supported by many databases. The Workflow pattern lets developers write the coordination logic in code that looks mostly like normal sequential code. There is also a two-phase message pattern described as a cleaner alternative to the traditional Outbox pattern, which is a technique for reliably publishing events when a database write happens.
DTM works across multiple languages. SDKs exist for Go, Java, PHP, C#, Python, and Node.js, so teams are not locked into any single technology. On the database side it supports MySQL, MariaDB, PostgreSQL, Redis, and MongoDB. It is built in Go and can scale horizontally for high-traffic situations.
Real-world users listed in the README include Tencent and Bytedance, both large technology companies, suggesting the project has been tested in demanding environments.
The quick-start example in the README shows a bank transfer scenario: money moves out of one account and into another across two separate microservices, with automatic rollback if the transfer-in step fails.
The project is open source and available under a permissive license.
Where it fits
- Implement a reliable bank-transfer flow across two microservices so money is never lost or double-debited even if one service crashes mid-transfer.
- Add SAGA-pattern rollback to a multi-step order checkout that touches an inventory service, a payment service, and a shipping service.
- Replace a fragile Outbox pattern implementation with DTM's two-phase message approach for reliable event publishing after a database write.
- Coordinate a TCC transaction across a Go and a Java microservice without rewriting either service in the same language.