Distribution Transaction Management in Microservices

Distribution Transaction Management in Microservices

To Manages the transaction in the distributed microservices, it involves handling transactions in each microservice to ensure the principles of ACID (Atomicity, Consistency, Isolation, Durability) are maintained across the entire system.

Atomicity:

Consistency:

Isolation:

Durability:

In the traditional approach, the use of the Two-Phase Commit (2PC) protocol ensures the adherence to ACID properties, maintaining a centralized network structure. When initiating a transaction, the first phase involves checking the availability of the databases. In this 'vote' phase, 2PC sends requests to the databases to confirm their readiness. If the databases acknowledge the request, the transaction proceeds.

However, during the execution of the transaction, a notable drawback emerges: the locking of tables. To maintain consistency, the tables are locked during the insertion of data. This locking mechanism introduces performance issues, causing increased latency in the overall process.

Furthermore, even after the vote phase, challenges may arise. If one of the database servers fails during the data insertion process, the transaction still proceeds, potentially leading to inconsistent data thus, saga design pattern comes into play.

The Saga design pattern emerges as a decentralized network solution specifically tailored for distributed microservices, and it is employed in Spring Cloud. It encompasses two approaches: Orchestration and Choreography patterns.

Orchestration pattern:

Here, customer assumes the role of the orchestrator, taking charge of managing the flow and consistency of a series of operations. The customer's involvement in the orchestration pattern includes initiating requests, receiving acknowledgments, and making decisions to ensure a coherent transaction experience.

The sequence begins with the customer sending a request to check the availability of a product. Upon receiving an acknowledgment confirming the product's availability, the customer proceeds by sending a payment request. Once the payment is acknowledged, the orchestration continues with the initiation of a notification service.

The orchestration pattern follows a centralized network mode and maintains tightly coupling with all services and it acts a decision making in the flow of transaction.

Choreography patterns:

The choreography pattern ensures loose coupling among services. In case of a service failure, the pattern initiates the transaction from that point, facilitating a decentralized network. Fault-tolerant communication relies on events.