健康检查模式架构
Architecture
健康检查模式架构图,展示负载均衡器探针、验证数据库、缓存、磁盘和依赖状态的深度健康检查、自动实例轮换以及与 PagerDuty 集成的连续故障告警。该模板模拟实现自愈系统的健康监控基础设施,不健康的实例自动从轮换中移除并通知运维团队。对于构建具有适当可观测性的生产就绪服务至关重要。
完整 FlowZap 代码
LoadBalancer { # Load Balancer
n1: circle label:"Health Check Timer"
n2: rectangle label:"Send Health Probe"
n3: rectangle label:"Evaluate Response"
n4: diamond label:"Instance Healthy?"
n5: rectangle label:"Keep in Rotation"
n6: rectangle label:"Remove from Rotation"
n7: rectangle label:"Update Routing Table"
n1.handle(right) -> n2.handle(left) [label="Every 10s"]
n2.handle(bottom) -> ServiceA.n8.handle(top) [label="GET /health"]
n2.handle(bottom) -> ServiceB.n12.handle(top) [label="GET /health"]
n3.handle(right) -> n4.handle(left)
n4.handle(right) -> n5.handle(left) [label="200 OK"]
n4.handle(bottom) -> n6.handle(top) [label="Timeout/5xx"]
n5.handle(right) -> n7.handle(left)
n6.handle(right) -> n7.handle(left)
}
ServiceA { # Service A
n8: rectangle label:"Check Database Connection"
n9: rectangle label:"Check Redis Connection"
n10: rectangle label:"Check Disk Space"
n11: rectangle label:"Return Health Status"
n8.handle(right) -> n9.handle(left) [label="DB OK"]
n9.handle(right) -> n10.handle(left) [label="Cache OK"]
n10.handle(right) -> n11.handle(left) [label="Disk OK"]
n11.handle(top) -> LoadBalancer.n3.handle(bottom) [label="Status JSON"]
}
ServiceB { # Service B
n12: rectangle label:"Check API Dependencies"
n13: rectangle label:"Check Message Queue"
n14: rectangle label:"Check Memory Usage"
n15: rectangle label:"Return Health Status"
n12.handle(right) -> n13.handle(left) [label="APIs OK"]
n13.handle(right) -> n14.handle(left) [label="Queue OK"]
n14.handle(right) -> n15.handle(left) [label="Memory OK"]
n15.handle(top) -> LoadBalancer.n3.handle(bottom) [label="Status JSON"]
}
Alerting { # Alerting System
n16: rectangle label:"Monitor Health Trends"
n17: diamond label:"Consecutive Failures?"
n18: rectangle label:"Send PagerDuty Alert"
n19: rectangle label:"Log Health Metric"
n16.handle(right) -> n17.handle(left)
n17.handle(right) -> n18.handle(left) [label="3+ Failures"]
n17.handle(bottom) -> n19.handle(top) [label="Below Threshold"]
n7.handle(bottom) -> Alerting.n16.handle(top) [label="Status Change"]
}
为什么需要这个工作流?
Load balancers that route traffic to unhealthy instances cause user-facing errors. Deep health checks verify not just that the process is running, but that all critical dependencies (database, cache, disk, external APIs) are functioning—enabling automatic instance rotation and proactive alerting before users are affected.
工作原理
- Step 1: The load balancer sends periodic health probes (GET /health) to each service instance.
- Step 2: Each service checks its database connection, cache connectivity, disk space, and memory usage.
- Step 3: A JSON health status is returned with individual component statuses.
- Step 4: Healthy instances remain in the load balancer rotation; unhealthy ones are removed.
- Step 5: The alerting system monitors health trends and fires alerts on consecutive failures.
- Step 6: PagerDuty notifications are sent when failure thresholds are exceeded.
替代方案
Simple TCP health checks only verify the process is listening. Liveness probes in Kubernetes restart unhealthy pods. Readiness probes control traffic routing. This template shows deep application-level health checks with alerting integration.
Key Facts
| Template Name | 健康检查模式架构 |
| Category | Architecture |
| Steps | 6 workflow steps |
| Format | FlowZap Code (.fz file) |
相关模板
微服务 API 网关架构
Architecture
微服务 API 网关架构图,展示请求路由、JWT 身份验证、速率限制、服务发现以及跨分布式后端服务的响应聚合。该模板模拟微服务生态系统中所有客户端流量的入口点,在请求到达内部服务之前执行安全策略。适合设计具有集中式横切关注点的可扩展 API 基础设施的平台工程师。
微服务每服务独立数据库架构
Architecture
每服务独立数据库架构图,每个微服务拥有其专用数据存储,通过 Kafka 进行事件驱动同步以实现跨服务数据一致性。该模板展示了微服务数据隔离的核心原则,展示 PostgreSQL 和 MongoDB 如何在多语言持久化策略中共存。对于在保持最终一致性的同时强制服务自治的架构师至关重要。
按业务能力分解微服务架构
Architecture
按业务能力组织的微服务分解架构图:身份认证、产品目录、定价和订单履行,每个都有独立的数据存储和 API。该模板展示如何将单体应用拆分为与业务领域对齐的服务,使用 Backend-for-Frontend (BFF) 模式进行客户端特定的聚合。适合规划领域驱动微服务边界的架构师。
微服务绞杀者模式迁移架构
Architecture
绞杀者模式迁移架构图,展示使用路由层在新旧系统之间分流流量,逐步用新微服务替换遗留单体应用。该模板模拟经过验证的迁移策略,新功能作为微服务构建,遗留端点逐步退役。对于在不进行高风险大爆炸重写的情况下现代化遗留系统的团队至关重要。