欢迎使用 FlowZap,快速、清晰、掌控的绘图应用。

Saga 订单履行架构

Architecture

订单履行 Saga 架构图,包含四个顺序步骤:客户验证、库存预留、支付授权和发货创建,以及在失败时反转已完成步骤的补偿链。该模板将端到端订单生命周期建模为 Saga,展示每个服务如何参与事务以及补偿操作如何维护数据一致性。适合设计可靠订单处理管道的电商架构师。

完整 FlowZap 代码

OrderSaga { # Order Fulfillment Saga
n1: circle label:"Order Received"
n2: rectangle label:"Validate Order"
n3: rectangle label:"Step 1: Verify Customer"
n4: rectangle label:"Step 2: Check Inventory"
n5: rectangle label:"Step 3: Authorize Payment"
n6: rectangle label:"Step 4: Ship Order"
n7: diamond label:"Saga Complete?"
n8: rectangle label:"Finalize Order"
n9: rectangle label:"Trigger Compensation Chain"
n10: circle label:"Order Fulfilled"
n1.handle(right) -> n2.handle(left)
n2.handle(right) -> n3.handle(left) [label="Valid"]
n3.handle(right) -> n4.handle(left) [label="Verified"]
n4.handle(right) -> n5.handle(left) [label="In Stock"]
n5.handle(right) -> n6.handle(left) [label="Authorized"]
n6.handle(right) -> n7.handle(left)
n7.handle(right) -> n8.handle(left) [label="Success"]
n7.handle(bottom) -> n9.handle(top) [label="Failure"]
n8.handle(right) -> n10.handle(left)
n3.handle(bottom) -> Services.n11.handle(top) [label="Verify"]
n4.handle(bottom) -> Services.n12.handle(top) [label="Reserve"]
n5.handle(bottom) -> Services.n13.handle(top) [label="Charge"]
n6.handle(bottom) -> Services.n14.handle(top) [label="Ship"]
}
Services { # Participating Services
n11: rectangle label:"Customer Service"
n12: rectangle label:"Inventory Service"
n13: rectangle label:"Payment Service"
n14: rectangle label:"Shipping Service"
n11.handle(top) -> OrderSaga.n4.handle(bottom) [label="Customer OK"]
n12.handle(top) -> OrderSaga.n5.handle(bottom) [label="Reserved"]
n13.handle(top) -> OrderSaga.n6.handle(bottom) [label="Charged"]
n14.handle(top) -> OrderSaga.n7.handle(bottom) [label="Shipped"]
}
Compensations { # Compensation Actions
n15: rectangle label:"Reverse Payment"
n16: rectangle label:"Release Inventory"
n17: rectangle label:"Notify Customer"
n18: circle label:"Saga Rolled Back"
n15.handle(right) -> n16.handle(left) [label="Refund"]
n16.handle(right) -> n17.handle(left) [label="Unreserve"]
n17.handle(right) -> n18.handle(left) [label="Apology Email"]
n9.handle(bottom) -> Compensations.n15.handle(top) [label="Compensate"]
}

为什么需要这个工作流?

E-commerce order fulfillment spans customer verification, inventory management, payment processing, and shipping—each owned by a different service. A saga ensures the entire fulfillment pipeline either completes successfully or rolls back cleanly, preventing scenarios like charging customers for out-of-stock items.

工作原理

  1. Step 1: The order is validated and the fulfillment saga begins.
  2. Step 2: Step 1: Customer Service verifies the customer account and shipping address.
  3. Step 3: Step 2: Inventory Service checks stock availability and reserves items.
  4. Step 4: Step 3: Payment Service authorizes and captures the payment.
  5. Step 5: Step 4: Shipping Service creates a shipment and generates tracking.
  6. Step 6: On failure at any step, the compensation chain reverses payment, releases inventory, and notifies the customer.

替代方案

Synchronous orchestration with rollback is simpler but creates long-running transactions. Event-driven choreography distributes the logic but is harder to debug. This template shows the orchestrated saga approach for order fulfillment.

Key Facts

Template NameSaga 订单履行架构
CategoryArchitecture
Steps6 workflow steps
FormatFlowZap Code (.fz file)

相关模板

Saga 编排模式架构

Architecture

Saga 编排架构图,中央编排器协调跨订单、库存和支付服务的多步骤分布式事务,具有专用的补偿链用于失败时的回滚。该模板模拟基于编排的 Saga 模式,单个协调器管理事务生命周期并在任何步骤失败时触发补偿操作。对于实施不使用两阶段提交的可靠分布式事务的架构师至关重要。

Saga 旅行预订架构

Architecture

旅行预订 Saga 架构图,将航班、酒店和租车预订编排为单一分布式事务,任何预订步骤失败时自动补偿取消所有预订。该模板模拟经典的 Saga 用例,多个独立服务必须全部成功或全部回滚,确保旅客不会出现部分预订。非常适合用真实业务场景演示 Saga 模式。

Saga 编舞模式架构

Architecture

Saga 编舞架构图,订单、支付和库存服务通过领域事件协调而无需中央编排器,每个服务发布和订阅驱动事务前进或触发补偿的事件。该模板模拟去中心化的 Saga 方法,服务自主响应事件,减少单点故障但增加了跟踪 Saga 状态的复杂性。适合偏好服务自治而非集中控制的团队。

Saga 分布式事务架构

Architecture

分布式事务架构图,实现两阶段提交协议,事务协调器向参与服务发送准备和提交消息,任何投票失败时执行全局中止。该模板可视化经典的 2PC 协议,用于多个服务间需要强一致性的场景,展示准备、投票和提交/中止阶段。对于理解微服务架构中分布式共识权衡至关重要。

微服务 API 网关架构

Architecture

微服务 API 网关架构图,展示请求路由、JWT 身份验证、速率限制、服务发现以及跨分布式后端服务的响应聚合。该模板模拟微服务生态系统中所有客户端流量的入口点,在请求到达内部服务之前执行安全策略。适合设计具有集中式横切关注点的可扩展 API 基础设施的平台工程师。

微服务服务网格架构

Architecture

服务网格架构图,展示 Istio 或 Linkerd 边车代理处理 mTLS 加密、流量策略、熔断器和跨微服务的分布式追踪。该模板可视化服务网格如何将网络关注点从应用代码中抽象出来,实现服务间的零信任通信。对于采用服务网格基础设施以提升可观测性和安全性的团队至关重要。

返回所有模板