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

Saga 旅行预订架构

Architecture

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

完整 FlowZap 代码

BookingAPI { # Booking API
n1: circle label:"Book Travel Package"
n2: rectangle label:"Validate Booking Request"
n3: rectangle label:"Start Booking Saga"
n4: rectangle label:"Return Booking Status"
n5: circle label:"End"
n1.handle(right) -> n2.handle(left)
n2.handle(right) -> n3.handle(left) [label="Valid"]
n3.handle(bottom) -> Saga.n6.handle(top) [label="Execute"]
n4.handle(right) -> n5.handle(left)
}
Saga { # Saga Orchestrator
n6: rectangle label:"Step 1: Book Flight"
n7: rectangle label:"Step 2: Book Hotel"
n8: rectangle label:"Step 3: Book Car Rental"
n9: diamond label:"All Bookings OK?"
n10: rectangle label:"Confirm All Reservations"
n11: rectangle label:"Compensate Failed Steps"
n6.handle(right) -> n7.handle(left) [label="Flight OK"]
n7.handle(right) -> n8.handle(left) [label="Hotel OK"]
n8.handle(right) -> n9.handle(left)
n9.handle(right) -> n10.handle(left) [label="All Success"]
n9.handle(bottom) -> n11.handle(top) [label="Any Failed"]
n10.handle(top) -> BookingAPI.n4.handle(bottom) [label="Confirmed"]
n11.handle(top) -> BookingAPI.n4.handle(bottom) [label="Cancelled"]
n6.handle(bottom) -> FlightService.n12.handle(top) [label="Reserve"]
n7.handle(bottom) -> HotelService.n14.handle(top) [label="Reserve"]
n8.handle(bottom) -> CarService.n16.handle(top) [label="Reserve"]
}
FlightService { # Flight Service
n12: rectangle label:"Reserve Flight Seat"
n13: rectangle label:"Cancel Flight (Compensate)"
n12.handle(top) -> Saga.n7.handle(bottom) [label="Reservation ID"]
n13.handle(top) -> Saga.n11.handle(bottom) [label="Cancelled"]
}
HotelService { # Hotel Service
n14: rectangle label:"Reserve Hotel Room"
n15: rectangle label:"Cancel Hotel (Compensate)"
n14.handle(top) -> Saga.n8.handle(bottom) [label="Reservation ID"]
n15.handle(top) -> Saga.n11.handle(bottom) [label="Cancelled"]
}
CarService { # Car Rental Service
n16: rectangle label:"Reserve Car"
n17: rectangle label:"Cancel Car (Compensate)"
n16.handle(top) -> Saga.n9.handle(bottom) [label="Reservation ID"]
n17.handle(top) -> Saga.n11.handle(bottom) [label="Cancelled"]
}

为什么需要这个工作流?

Travel bookings involve multiple independent services (flights, hotels, car rentals) that must either all succeed or all be cancelled—a partial booking is worse than no booking. The saga pattern ensures atomicity across these services without distributed transactions, with automatic compensation for failed steps.

工作原理

  1. Step 1: The booking API validates the travel package request and starts the saga.
  2. Step 2: Step 1: The Flight Service reserves a seat on the requested flight.
  3. Step 3: Step 2: The Hotel Service reserves a room for the travel dates.
  4. Step 4: Step 3: The Car Rental Service reserves a vehicle at the destination.
  5. Step 5: If all reservations succeed, all are confirmed simultaneously.
  6. Step 6: If any reservation fails, compensation actions cancel all previously made reservations.

替代方案

Manual booking with separate confirmations risks partial bookings. Travel aggregators handle this internally but charge commissions. This template demonstrates the saga pattern with the classic travel booking use case.

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,展示每个服务如何参与事务以及补偿操作如何维护数据一致性。适合设计可靠订单处理管道的电商架构师。

无服务器 Step Functions 编排架构

Architecture

AWS Step Functions 编排架构图,展示状态机工作流,包括选择状态、并行处理、等待回调模式以及失败步骤的补偿回滚。该模板模拟无服务器工作流编排,复杂的多步骤流程定义为具有内置错误处理和重试逻辑的状态机。对于构建需要人工审批或长时间运行流程的可靠无服务器工作流的团队至关重要。

Saga 分布式事务架构

Architecture

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

微服务 API 网关架构

Architecture

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

返回所有模板