Solution

For many Microservices based applications, the solution to achieve transactions is to use an event-driven architecture wherein state change is captured as events and published. Other services subscribe to these events and change their own data, which might lead to more events being published. Although Azure services such as Azure Service Bus Topics can be used to publish events, there are several other challenges with the approach such as how to atomically update state and publish events. Some of the approaches for maintaining atomicity are using the database as a message queue, transaction log mining, and event sourcing which are difficult to implement.

Eventual consistency of data may be achieved easily by the compensating transaction pattern. A common approach to realize this pattern is to use a workflow. A transactional operation should be designed as chain of separate work-steps that form a chain. If the operation fails at any point, the workflow rewinds back through the work-steps it has completed and reverses the work by using the compensator of each work-step.

The following diagram depicts work-steps and compensation steps in a multi-step workflow:

Compensating Transaction (Solution)

Using Azure Service Bus Queues auto forwarding property, such a workflow can be built easily. A working prototype of this pattern is available at Clemens Vasters' blog: https://github.com/Azure-Samples/azure-servicebus-messaging-samples/tree/master/AtomicTransactions.

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
3.145.20.87