top of page

Distributed transactions in the Cloud - part I

One of the most common problem that a microservice architecture is facing is performing a transaction across multiple services.


A distributed architecture is based on a number of small components, functions or services, that works independently and update their corresponding data sources with no concerns for other components activity.


As a result, the data committed to the data store in a distributed transaction may became in-consistent since some components activities may completes successfully while other fails.


The solution to this problem is by implementing the Saga design pattern as described in the link from below:



A saga is a sequence of transactions that updates each service and publishes a message or event to trigger the next transaction step. If a step fails, the saga executes compensating transactions that counteract the preceding transactions.

There are two common saga implementation approaches, choreography and orchestration.


Choreography

Choreography is a way to coordinate sagas where participants exchange events without a centralized point of control. With choreography, each local transaction publishes domain events that trigger local transactions in other services.


Orchestration


Orchestration is a way to coordinate sagas where a centralized controller tells the saga participants what local transactions to execute.


The saga orchestrator handles all the transactions and tells the participants which operation to perform based on events.


The orchestrator executes saga requests, stores and interprets the states of each task, and handles failure recovery with compensating transactions.



Sample code

  1. Atomic transactions with the Service Bus



This project is using the service bus queues and a Saga choreography pattern to create a framework that takes care of committing or rolling back distributed transactions.


Each transaction it is enrolled into a workflow (topology) that specifies what is the next step of execution to follow for either a success or a failure result.


If a transaction fails, the message it is forwarded from the dead letter queue to the Cancel queue.


2. Saga orchestration serverless



This is an orchestration saga executed with Azure Durable functions and Azure Event Hub for sending the events between functions.


The design is storing the failed events into a Cosmos database and sends compensatory events to trigger compensatory transactions: in the image from below, event 11 triggers the orchestrator to send event 13 and rollback the "Transfer" transaction after the "Receipt" transaction failed.




Coming next...

In the next article I will describe a framework I have created using the Azure durable functions to commit and rollback automatically the enrolled transactions processed either in sequence or in parallel.


21 views0 comments

Recent Posts

See All

Distributed transactions in the Cloud - part II

Last year I worked on several Cloud integrations between various vendor applications used by an educational institution. These integrations make use of a disconnected architecture where a service bus

Azure Site-to-Site using VPN Gateway configuration

Azure Site-to-Site VPN configuration This configuration will be helpful when you need to test an application deployed in a VM from Azure Cloud which connects to a VM located on-premises. This configur

  • Facebook profile
  • Twitter profile
  • LinkedIn Profile

©2020 by PlanetIT. Proudly created with Wix.com

bottom of page