Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is event sourcing an enhanced pattern of choreography-based SAGA pattern?

These days I am researching the Microservice inter-service communication patterns. So during my research, I found that there are two patterns called SAGA and event sourcing. But I couldn't find a resource on the internet to learn the difference between the two patterns. I mean I know event sourcing will capture the history of the event with the aid of an event store. So as per my understandings, I feel that event sourcing is like an extended version of choreography-based SAGA pattern. So I need to clarify is my argument acceptable or not. I will attach sample diagrams of the two patterns which I found on the internet below. Please use those diagrams during any of your explanations.

Choreography based SAGA Implementation

Event Sourcing

References

like image 747
Hasindu Dahanayake Avatar asked Apr 02 '21 11:04

Hasindu Dahanayake


People also ask

What is the event sourcing pattern?

Solution. The Event Sourcing pattern defines an approach to handling operations on data that's driven by a sequence of events, each of which is recorded in an append-only store.

What does saga pattern mean?

The saga pattern is a failure management pattern that helps establish consistency in distributed applications, and coordinates transactions between multiple microservices to maintain data consistency.

What is Saga pattern in microservices?

The Saga design pattern is a way to manage data consistency across microservices in distributed transaction scenarios. A saga is a sequence of transactions that updates each service and publishes a message or event to trigger the next transaction step.

What is the difference between saga orchestration and Saga choreography?

There are two ways of coordination sagas: Choreography - each local transaction publishes domain events that trigger local transactions in other services. Orchestration - an orchestrator (object) tells the participants what local transactions to execute.

What is the difference between a choreography and orchestration Saga pattern?

A choreography saga pattern is a method to organise sagas where participants swap events without a centralized control point. On the other hand, an orchestration saga pattern is a method to coordinate sagas through a centralized controller that informs the saga participants what local transactions should be executed.

What is choreograph-based saga approach in Salesforce?

In Choreograph-based saga approach, each local transaction emits domain events. This events then triggers local transaction in other services subscribed to these events. So assuming there are three services A, B and C. When a local transaction occurs in A, it publishes an event that triggers a local transaction in B.

What is event choreography?

Event Choreography Choreography is driven by events from the various services within a system. Each service consumes events, performs an action, and publishes events. There is no centralized coordination or logic.

How choreography-based saga works in microservices?

How Choreography-based Saga Works in Microservices - Microservices . In this article we would explain how a Choreography-based Saga works in microservices. Then present a simple algorithm. In Choreograph-based saga approach, each local transaction emits domain events.


1 Answers

The two are compatible patterns that address different problems, Sagas handle workflow processes where as event sourcing addresses how state is stored. Sagas provide a mechanism for handling a multi-step process and rolling back should steps fail (like a workflow). Where as Event Sourcing is the process of encoding the state of an entity by recording all its past changes.

Sagas

Lets say we are booking a holiday, we need to book flights, a hotel and hire a car. each of these processes is handled by a different microservice.

We could create a microservice named BookingSaga which would be responsible for keeping track of the state of each booking. When we make a booking the BookingSaga service would

  • book the hotel
  • book the flight
  • book the car

these can reply in any order, but if any one fails the BookingSaga would then begin a rollback and cancel any that had already been booked.

https://microservices.io/patterns/data/saga.html

Event Sourcing

Event sourcing keeps track of the state of some entity by recording the changes that have happened to it.

  • Object A Name changed to "dave"
  • Object A Age Changed to 3
  • Object A Named changed to "sue"

So we can see that Object A has a name of "sue" and an Age of 3 at the end of all the events. https://microservices.io/patterns/data/event-sourcing.html

like image 170
Ross G Avatar answered Oct 08 '22 14:10

Ross G