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

熔断器弹性架构

Architecture

熔断器弹性架构图,展示完整的状态机,包括关闭、打开和半开状态、故障阈值跟踪、恢复计时器以及保护服务免受级联故障的降级响应策略。该模板详细可视化熔断器模式,包括熔断器如何根据成功和失败计数在状态之间转换。对于构建在负载下优雅降级的容错微服务至关重要。

完整 FlowZap 代码

Client { # Client Service
n1: circle label:"Service Call"
n2: rectangle label:"Circuit Breaker Proxy"
n3: rectangle label:"Receive Response"
n4: circle label:"End"
n1.handle(right) -> n2.handle(left)
n2.handle(bottom) -> Breaker.n5.handle(top) [label="Check State"]
n3.handle(right) -> n4.handle(left)
}
Breaker { # Circuit Breaker
n5: diamond label:"Circuit State?"
n6: rectangle label:"Forward Request (Closed)"
n7: rectangle label:"Return Fallback (Open)"
n8: rectangle label:"Test Request (Half-Open)"
n9: rectangle label:"Track Success"
n10: rectangle label:"Track Failure"
n11: diamond label:"Failure Threshold?"
n12: rectangle label:"Trip Circuit Open"
n13: rectangle label:"Reset to Closed"
n14: rectangle label:"Start Recovery Timer"
n5.handle(right) -> n6.handle(left) [label="Closed"]
n5.handle(bottom) -> n7.handle(top) [label="Open"]
n5.handle(left) -> n8.handle(right) [label="Half-Open"]
n6.handle(bottom) -> Downstream.n15.handle(top) [label="Forward"]
n7.handle(top) -> Client.n3.handle(bottom) [label="Cached/Default"]
n8.handle(bottom) -> Downstream.n15.handle(top) [label="Probe"]
n9.handle(right) -> n13.handle(left) [label="Healthy"]
n10.handle(right) -> n11.handle(left)
n11.handle(right) -> n12.handle(left) [label="Exceeded"]
n11.handle(top) -> n6.handle(bottom) [label="Below"]
n12.handle(right) -> n14.handle(left) [label="Cooldown"]
n14.handle(top) -> n8.handle(bottom) [label="Timer Expired"]
}
Downstream { # Downstream Service
n15: rectangle label:"Process Request"
n16: diamond label:"Response OK?"
n17: rectangle label:"Return Success"
n18: rectangle label:"Return Error/Timeout"
n15.handle(right) -> n16.handle(left)
n16.handle(right) -> n17.handle(left) [label="200"]
n16.handle(bottom) -> n18.handle(top) [label="5xx/Timeout"]
n17.handle(top) -> Breaker.n9.handle(bottom) [label="Success"]
n18.handle(top) -> Breaker.n10.handle(bottom) [label="Failure"]
n17.handle(top) -> Client.n3.handle(bottom) [label="Response"]
}

为什么需要这个工作流?

When a downstream service fails, continuing to send requests wastes resources and can cascade failures across the entire system. The circuit breaker pattern detects failures, stops sending requests to unhealthy services, and automatically recovers when the service heals—preventing cascading failures and enabling graceful degradation.

工作原理

  1. Step 1: The circuit breaker proxy intercepts all outbound requests to the downstream service.
  2. Step 2: In the closed state, requests pass through normally and success/failure counts are tracked.
  3. Step 3: When failures exceed the configured threshold, the circuit trips to the open state.
  4. Step 4: In the open state, requests immediately return a fallback response without contacting the downstream service.
  5. Step 5: After a recovery timer expires, the circuit enters the half-open state and sends a test request.
  6. Step 6: If the test succeeds, the circuit resets to closed; if it fails, it returns to open.

替代方案

Simple retry logic does not prevent cascading failures. Timeout-based approaches waste resources waiting. Libraries like Resilience4j, Polly, or Hystrix implement circuit breakers. This template visualizes the complete state machine for understanding the pattern.

Key Facts

Template Name熔断器弹性架构
CategoryArchitecture
Steps6 workflow steps
FormatFlowZap Code (.fz file)

相关模板

无服务器 Step Functions 编排架构

Architecture

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

舱壁隔离架构

Architecture

舱壁隔离架构图,为关键、标准和批处理工作负载提供独立的线程池,每个都有独立的连接池、耗尽检测和背压策略,防止一个工作负载饿死其他工作负载。该模板模拟受船体舱壁启发的隔离模式,资源隔离确保一个组件的故障或过载不会级联到其他组件。对于需要为高优先级操作保证可用性的系统至关重要。

指数退避重试架构

Architecture

指数退避重试架构图,展示完整的重试策略引擎,包括可重试与不可重试错误分类、带抖动的指数延迟计算、最大重试阈值和优雅的耗尽处理。该模板模拟处理分布式系统中瞬态故障的基本弹性模式,通过随机退避延迟防止惊群问题。对于云架构中任何服务间通信都是基础性的。

Ambassador 模式架构

Architecture

Ambassador 模式架构图,本地代理边车处理身份验证头注入、熔断、重试逻辑和对外部第三方 API 出站请求的指标收集。该模板模拟 Ambassador 模式,与应用一起运行的辅助服务卸载外部通信的横切关注点。适合与需要弹性包装器的不可靠第三方服务集成的团队。

断路器工作流

patterns

断路器弹性模式,包含闭合、打开和半开状态,用于保护服务免受级联故障,并带有自动恢复测试。

微服务 API 网关架构

Architecture

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

返回所有模板