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

微服务 API 网关架构

Architecture

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

完整 FlowZap 代码

Client { # Client Application
n1: circle label:"Incoming Request"
n2: rectangle label:"Load Balancer"
n3: rectangle label:"Receive API Response"
n4: circle label:"End"
n1.handle(right) -> n2.handle(left)
n2.handle(bottom) -> Gateway.n5.handle(top) [label="Route Request"]
n3.handle(right) -> n4.handle(left)
}
Gateway { # API Gateway
n5: rectangle label:"Authenticate JWT Token"
n6: diamond label:"Token Valid?"
n7: rectangle label:"Apply Rate Limiting"
n8: rectangle label:"Return 401 Unauthorized"
n9: diamond label:"Rate Limit OK?"
n10: rectangle label:"Route to Microservice"
n11: rectangle label:"Return 429 Throttled"
n12: rectangle label:"Aggregate Responses"
n5.handle(right) -> n6.handle(left)
n6.handle(right) -> n7.handle(left) [label="Yes"]
n6.handle(bottom) -> n8.handle(top) [label="No"]
n7.handle(right) -> n9.handle(left)
n8.handle(top) -> Client.n3.handle(bottom) [label="401"]
n9.handle(right) -> n10.handle(left) [label="Yes"]
n9.handle(bottom) -> n11.handle(top) [label="No"]
n10.handle(bottom) -> Services.n13.handle(top) [label="Forward"]
n11.handle(top) -> Client.n3.handle(bottom) [label="429"]
n12.handle(top) -> Client.n3.handle(bottom) [label="Response"]
}
Services { # Microservices Cluster
n13: rectangle label:"Service Discovery Lookup"
n14: rectangle label:"User Service"
n15: rectangle label:"Order Service"
n16: rectangle label:"Inventory Service"
n17: rectangle label:"Compose Response"
n13.handle(right) -> n14.handle(left) [label="Users"]
n13.handle(bottom) -> n15.handle(top) [label="Orders"]
n14.handle(right) -> n17.handle(left)
n15.handle(right) -> n16.handle(left) [label="Check Stock"]
n16.handle(right) -> n17.handle(left)
n17.handle(top) -> Gateway.n12.handle(bottom) [label="Aggregated"]
}

为什么需要这个工作流?

Without a centralized API gateway, every microservice must independently handle authentication, rate limiting, and request routing—leading to duplicated logic, inconsistent security policies, and operational complexity. An API gateway provides a single entry point that enforces cross-cutting concerns before requests reach backend services, reducing attack surface and simplifying client integration.

工作原理

  1. Step 1: Client sends a request through the load balancer to the API Gateway.
  2. Step 2: The gateway validates the JWT token and checks authentication status.
  3. Step 3: Rate limiting is applied based on client identity and configured thresholds.
  4. Step 4: Authenticated and throttled requests are routed to the appropriate microservice via service discovery.
  5. Step 5: Backend services process the request and return responses through the gateway for aggregation.
  6. Step 6: The gateway composes the final response and returns it to the client.

替代方案

Building authentication and rate limiting into each service leads to inconsistency and maintenance burden. Commercial API gateways like Kong or Apigee cost $10K-100K+/year. This FlowZap template helps teams visualize their gateway architecture before implementation.

Key Facts

Template Name微服务 API 网关架构
CategoryArchitecture
Steps6 workflow steps
FormatFlowZap Code (.fz file)

相关模板

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

Architecture

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

微服务服务发现架构

Architecture

服务发现架构图,展示 Consul 或 Eureka 注册中心、客户端负载均衡、健康检查心跳以及实例的自动注册和注销。该模板可视化微服务如何在没有硬编码端点的情况下动态定位彼此,实现弹性扩展和自愈基础设施。对于构建弹性服务间通信的平台团队至关重要。

微服务 Backend-for-Frontend (BFF) 架构

Architecture

Backend-for-Frontend 架构图,为 Web 和移动客户端提供独立的 BFF 层,每层针对其特定平台优化 API 响应,同时共享通用后端微服务。该模板展示如何通过按客户端类型定制数据聚合和负载优化来避免一刀切的 API。推荐给从共享微服务后端服务多个前端平台的团队。

事件驱动编排架构

Architecture

事件驱动编排架构图,微服务通过事件协调而无需中央编排器,订单、支付、库存和物流服务相互响应对方的领域事件。该模板模拟去中心化协调模式,每个服务只了解自己的职责并发布事件供其他服务消费。适合偏好服务自治而非集中式工作流控制的团队。

无服务器 API 后端架构

Architecture

无服务器 API 后端架构图,展示 API 网关、Lambda 授权函数、业务逻辑函数以及包括 DynamoDB、S3、SQS 和 SNS 在内的托管云服务,实现完全托管、自动扩展的后端。该模板模拟无服务器优先方法,完全消除基础设施管理,按调用付费并自动缩放至零。对于构建经济高效的事件驱动 API 后端的初创公司和团队至关重要。

Saga 编排模式架构

Architecture

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

返回所有模板