A distributed Saga is a collection of requests and compensating requests that represent a single business level action.
Saga pattern allows us to use 2 approaches for implementation :
Orchestration: As the name suggests, there is a central coordinator/orchestrator that handles all the microservice interactions. It transmits the events and responds to it. It calls the microservice-based on a workflow for a particular API action, and it invokes those microservice sequentially in order, wait for the response from one microservice before calling the other. Here microservices are tightly coupled as they are associated with the orchestrator. Removing any microservice in between is quite challenging as it impacts the overall workflow.
No alt text provided for this image
Choreography: This is another way in which the microservices interact with each other, the difference is to handle this interaction there is no separate coordinator or instructor who is needed to manage. Each microservice performs its action independently and decisions, logics, and interactions are decentralized managed by events. It provides low coupling of services and we can easily manage the addition/removal of services within a workflow without impacting other services in the workflow. This is also known as reactive architecture.
choreography pattern image
Use cases: When to react (chorography) v/s When to coordinate (orchestration)?
Choreography is preferred over Orchestration when we need :
lower coupling between the microservices. The orchestration pattern of communication is a Point-to-Point connection between the services and it increases complexity and any modification needs more work so that coordinator would be in synch to handle any new microservice in the existing workflow.
fast processing and easy modifications for any add/update feature.
An easy replay of events by using event sourcing/event store. At any point, it's possible for applications to read the history of events, and use it to materialize the current state of an entity by playing back and consuming all the events related to that entit