Saga

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. If a step fails, the saga executes compensating transactions that counteract the preceding transactions : https://docs.microsoft.com/en-us/azure/architecture/reference-architectures/saga/saga

  1. Context and problem

    Transactions within a single service are ACID (atomic, consistent, isolated, and durable), but cross-service data consistency requires a cross-service transaction management strategy.

  2. Solution

    Choreography pattern allows a transaction to be executed in parallel steps and/or in sequences.

    Features : Orchestration starts with an event and can end with an ending event (event as message, file transfer, entry in table, etc.); coordination is centralized; orchestrator is responsible for the integrity of the transaction.

    Sage pattern with centralized coordination
  3. Challenges

  • Hard to debug and complexity will grow the number of participants

  • Data can’t be rolled back because participants commit changes to their local DB

  • Very demanding pattern because need to implement countermeasures to reduce anomalies