DTC (Distributed Transaction)
Distributed Transaction Handling using Saga Orchestration Pattern.
Saga orchestration pattern is used to manage distributed transactions across microservices.
The system consists of independent microservices:
Order Service
Payment Service
Inventory Service
Delivery Service
Every action performed by a microservice has an associated compensating (rollback) action. Examples include:
Canceling a delivery
Reverting inventory updates
Reversing a payment
Canceling an order
T1, T2, T3, and T4 are separate local transactions, each executing within its own microservice. Together, they form a single distributed transaction managed by the Saga pattern.
Contineo initiates the distributed transaction when the outermost action is triggered (either by a browser request or a batch job). It registers the rollback handlers for each step in a common database accessible to all microservices.
If an error occurs in any microservice action:
The corresponding local transaction fails.
The registered rollback handlers are invoked in reverse order to maintain consistency.
Example Rollback Flow:
If Transaction 4 (Deliver Order) fails, the following rollback actions are executed in this sequence:Cancel Delivery
Revert Inventory Update
Reverse Payment
Cancel Order
Contineo handles rollback in the following ways:
If the action is a database operation with an entity specified and audit trail enabled, the operation is automatically rolled back by the Contineo framework using the audit trail.
In all other cases, the registered rollback handler for the action is explicitly called.