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

指数退避重试架构

Architecture

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

完整 FlowZap 代码

Caller { # Calling Service
n1: circle label:"Initiate Request"
n2: rectangle label:"Send HTTP Request"
n3: rectangle label:"Receive Response"
n4: circle label:"Request Complete"
n1.handle(right) -> n2.handle(left)
n2.handle(bottom) -> RetryPolicy.n5.handle(top) [label="Execute"]
n3.handle(right) -> n4.handle(left)
}
RetryPolicy { # Retry Policy Engine
n5: rectangle label:"Attempt Request"
n6: diamond label:"Response Status?"
n7: rectangle label:"Return Success"
n8: diamond label:"Retryable Error?"
n9: rectangle label:"Return Permanent Failure"
n10: rectangle label:"Calculate Backoff Delay"
n11: diamond label:"Max Retries Exceeded?"
n12: rectangle label:"Wait with Jitter"
n13: rectangle label:"Return Exhausted Error"
n5.handle(right) -> n6.handle(left)
n6.handle(right) -> n7.handle(left) [label="2xx"]
n6.handle(bottom) -> n8.handle(top) [label="Error"]
n7.handle(top) -> Caller.n3.handle(bottom) [label="Success"]
n8.handle(right) -> n10.handle(left) [label="429/503/Timeout"]
n8.handle(bottom) -> n9.handle(top) [label="400/401/404"]
n9.handle(top) -> Caller.n3.handle(bottom) [label="Non-Retryable"]
n10.handle(right) -> n11.handle(left) [label="2^n * base"]
n11.handle(bottom) -> n13.handle(top) [label="Yes"]
n11.handle(right) -> n12.handle(left) [label="No"]
n12.handle(top) -> n5.handle(bottom) [label="Retry"]
n13.handle(top) -> Caller.n3.handle(bottom) [label="Max Retries"]
}
Target { # Target Service
n14: rectangle label:"Process Request"
n15: diamond label:"Service Healthy?"
n16: rectangle label:"Return 200 OK"
n17: rectangle label:"Return 503 Unavailable"
n14.handle(right) -> n15.handle(left)
n15.handle(right) -> n16.handle(left) [label="Yes"]
n15.handle(bottom) -> n17.handle(top) [label="No"]
n16.handle(top) -> RetryPolicy.n6.handle(bottom) [label="Success"]
n17.handle(top) -> RetryPolicy.n6.handle(bottom) [label="Error"]
n5.handle(bottom) -> Target.n14.handle(top) [label="HTTP"]
}

为什么需要这个工作流?

Transient failures (network blips, temporary overloads) are inevitable in distributed systems. Naive retry strategies with fixed intervals cause thundering herd problems where all clients retry simultaneously. Exponential backoff with jitter spreads retries over time, giving the failing service time to recover.

工作原理

  1. Step 1: The calling service sends a request to the target service.
  2. Step 2: If the response indicates a transient error (429, 503, timeout), the retry policy activates.
  3. Step 3: Non-retryable errors (400, 401, 404) are returned immediately without retry.
  4. Step 4: The backoff delay is calculated as 2^n × base_delay with random jitter.
  5. Step 5: If the maximum retry count is exceeded, an exhaustion error is returned to the caller.
  6. Step 6: Successful responses reset the retry counter for subsequent requests.

替代方案

Fixed-interval retries cause thundering herds. No retries mean transient failures become permanent. Circuit breakers complement retries by stopping attempts to known-failing services. This template shows the complete retry policy engine.

Key Facts

Template Name指数退避重试架构
CategoryArchitecture
Steps6 workflow steps
FormatFlowZap Code (.fz file)

相关模板

事件驱动死信队列架构

Architecture

死信队列架构图,展示重试策略、指数退避、最大重试阈值、失败消息的 DLQ 路由、运维告警和手动重处理工作流。该模板模拟异步消息系统的关键错误处理模式,确保处理失败时不会静默丢失任何消息。对于构建具有适当故障恢复机制的可靠事件驱动系统至关重要。

熔断器弹性架构

Architecture

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

舱壁隔离架构

Architecture

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

微服务 API 网关架构

Architecture

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

微服务服务网格架构

Architecture

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

微服务每服务独立数据库架构

Architecture

每服务独立数据库架构图,每个微服务拥有其专用数据存储,通过 Kafka 进行事件驱动同步以实现跨服务数据一致性。该模板展示了微服务数据隔离的核心原则,展示 PostgreSQL 和 MongoDB 如何在多语言持久化策略中共存。对于在保持最终一致性的同时强制服务自治的架构师至关重要。

返回所有模板