NOTE

2.5 Distributed Transaction Solution: Saga

1. What Is Saga - A distributed transaction solution that guarantees eventual consistency. 2. Saga Process - There are multiple transaction participants, and each participant has two pieces of logic: a forward operation and a reverse operation. - Divide the transaction into two phases.

Distributed SystemsCreated Updated 1 min readhistorical

This is a historical learning note and may contain outdated or incomplete understanding.

1. What Is Saga?

A distributed transaction solution that guarantees eventual consistency.

2. Saga Process

  • There are multiple transaction participants, and each participant has two pieces of logic: a forward operation and a reverse operation.
  • Divide the transaction into two phases:
    • In the first phase, each participant executes the forward operation.
    • The second phase depends on the result of the first phase.
      • If all forward operations execute successfully, the distributed transaction commits.
      • If any forward operation fails, go back and execute the reverse operations of the preceding participants.

3. TCC vs Saga

  • Similarities:
    • Both have two phases.
    • Both need to implement compensation operations.
  • Differences:
    • TCC is synchronous, while Saga is asynchronous (event-driven).
    • TCC needs to reserve resources in the first phase, while Saga does not.

4. Use Cases for Saga

  • Multiple services use multiple data sources, and each data source can be different.
  • Participants include other companies or legacy-system services that cannot provide the three interfaces required by the TCC model.
  • Business processes are long and have many steps.

5. Problems with Saga

Does not guarantee isolation.

6. Saga Implementation

6.1. Seata Saga Mode

7. References

Discussion

Sign in with GitHub to comment. Discussions are stored as GitHub Issues.View on GitHub