← 返回刚才阅读的位置

知识卡片

结构图卡 · 4359.b.1.a

Saga用补偿协调服务步骤

理解等级:高级

当跨服务事务确有必要,原书描述的 Saga 由协调服务逐步调用参与者并记录成败。若前一步成功、后一步失败,协调者向已成功的参与者发出“撤销先前请求”的补偿请求;常见实现会让各步先保持待定,直到整体成功再确认。补偿需要额外协调与网络通信,失败处理仍须设计,不能把跨服务流程等同于一次数据库原子回滚。

结构图:

flowchart LR
    M[协调服务记录步骤结果] --> A[服务A成功]
    A --> B{服务B结果}
    B -->|成功| C[确认整体结果]
    B -->|失败| D[请求A补偿先前操作]
    D --> E[跟踪补偿结果]
这张卡片看不懂?

已有反馈 · 0 条

    还没有人提交反馈。

    在整书笔记中的位置

    原书出处 · 1 处

    • Microservices Architecture · 查看原书依据

      If the first part of the transaction succeeds but the second part fails, the mediator must send a request to all other participating services of the transaction that were successful and tell them to undo the previous request.

    参考来源

    - 位置:《Fundamentals of Software Architecture》原书第18章《Microservices Architecture》(阅读计划第21项,单元12;源文件:`OEBPS/ch18.html`) - 结论依据:原书图18-11、18-12及正文给出协调、记录、失败后请求成功参与者撤销、待定状态和额外通信;“跟踪补偿结果”和区别数据库回滚是机制推断,并非书中承诺的成功保证。 - 原始内容:If the first part of the transaction succeeds but the second part fails, the mediator must send a request to all other participating services of the transaction that were successful and tell them to undo the previous request.