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

1

11

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

Washwoman answered 2/4, 2021 at 11:29 Comment(0)
T
13

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

Tombstone answered 2/4, 2021 at 13:8 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.