distributedsystem/microservice microservicepatterns

Microservices Patterns: The Saga Pattern | Cloud Native Daily
Mastering Distributed Transactions: From 2PC to the Saga Pattern | by Aseem | Medium

Intro

Widely Used in Microservices.
Asynchronous.

A saga is a sequence of local transactions. Each local transaction updates the database and publishes a message or event to trigger the next local transaction in the saga. If a local transaction fails because it violates a business rule then the saga executes a series of compensating transactions that undo the changes that were made by the preceding local transactions.

Coordination

There are two common implementation approaches:

  • Choreography: Each local transaction publishes domain events that trigger local transactions in other services.
  • Orchestration: An orchestrator tells the participants what local transactions to execute.