Business Classification and Distributed Transaction Solutions with DTM, SEATA, and RocketMQ
The article classifies common microservice business scenarios, matches each with suitable distributed transaction patterns such as reliable messages, TCC, SAGA, and XA, and demonstrates practical implementations using DTM, SEATA, and RocketMQ with code examples and a feature comparison table.
When a system adopts a service/micro‑service architecture, the original single‑instance ACID transactions become unsuitable, so distributed transaction mechanisms are required to maintain atomicity across services.
The article groups typical business scenarios and recommends the most appropriate distributed transaction solution for each:
Combining multiple micro‑services into an atomic operation – use reliable message (e.g., RocketMQ, RabbitMQ) and wait for queue acknowledgment.
Local transaction plus multiple services – use local message or transaction message to ensure atomicity between the local DB and messages.
Order‑related high‑consistency business – adopt the TCC pattern, freezing funds in the Try phase and confirming or canceling in subsequent phases.
Low‑consistency but roll‑backable business – apply the SAGA pattern, which uses forward actions and compensating actions.
Long‑running global transactions – prefer reliable messages or SAGA; TCC and XA are less suitable.
Low‑concurrency business requiring rollback – choose XA if the local DB supports XA interfaces.
In practice, the article suggests selecting an open‑source framework to implement the chosen pattern, highlighting DTM (written in Go), SEATA (Java), and RocketMQ (Java). DTM supports TCC, SAGA, XA, reliable messages, and transaction messages.
Reliable Message Example (DTM)
msg := dtmcli.NewMsg(DtmServer, gid).
Add(Busi+"/ObtainCoupon", req).
Add(Busi+"/ObtainVip", req)
err := msg.Submit()DTM guarantees both ObtainCoupon and ObtainVip are called; any failure triggers retries until success.
SAGA Example (DTM)
saga := dtmcli.NewSaga(DtmServer, gid).
Add(Busi+"/AdjustIntegral", Busi+"/AdjustIntegralRevert", req).
Add(Busi+"/AuthCourse", Busi+"/AuthCourseRevert", req)
saga.WaitResult = true
err := saga.Submit()DTM executes AdjustIntegral and AuthCourse sequentially; if an error occurs, it invokes the compensating actions AuthCourseRevert and AdjustIntegralRevert .
The article also provides a comparison table between DTM and SEATA, covering supported languages, exception handling, transaction types (TCC, XA, AT, SAGA), transaction messages, and communication protocols.
In summary, DTM offers a simple, multi‑language, HTTP‑based solution for distributed transactions, simplifying microservice development compared with more complex stacks like SEATA + RocketMQ.
IT Architects Alliance
Discussion and exchange on system, internet, large‑scale distributed, high‑availability, and high‑performance architectures, as well as big data, machine learning, AI, and architecture adjustments with internet technologies. Includes real‑world large‑scale architecture case studies. Open to architects who have ideas and enjoy sharing.
How this landed with the community
Was this worth your time?
0 Comments
Thoughtful readers leave field notes, pushback, and hard-won operational detail here.