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

GraphQL 联邦架构

Architecture

GraphQL 联邦架构图,Apollo 网关构建查询计划并扇出到用户、产品和评论子图,每个子图拥有自己的模式和数据库,响应拼接为统一的 GraphQL 结果。该模板模拟联邦 GraphQL 方法,多个团队独立开发和部署其子图,而客户端看到单一统一的 API。适合跨多个团队和服务扩展 GraphQL 的组织。

完整 FlowZap 代码

Client { # Client Application
n1: circle label:"GraphQL Query"
n2: rectangle label:"Send to Gateway"
n3: rectangle label:"Receive Unified Response"
n4: circle label:"Render UI"
n1.handle(right) -> n2.handle(left)
n2.handle(bottom) -> Gateway.n5.handle(top) [label="POST /graphql"]
n3.handle(right) -> n4.handle(left)
}
Gateway { # Apollo Federation Gateway
n5: rectangle label:"Parse GraphQL Query"
n6: rectangle label:"Build Query Plan"
n7: rectangle label:"Fan-Out to Subgraphs"
n8: rectangle label:"Merge Responses"
n9: rectangle label:"Return Unified Result"
n5.handle(right) -> n6.handle(left) [label="AST"]
n6.handle(right) -> n7.handle(left) [label="Execution Plan"]
n7.handle(bottom) -> Subgraphs.n10.handle(top) [label="User Fields"]
n7.handle(bottom) -> Subgraphs.n12.handle(top) [label="Product Fields"]
n7.handle(bottom) -> Subgraphs.n14.handle(top) [label="Review Fields"]
n8.handle(right) -> n9.handle(left) [label="Stitched"]
n9.handle(top) -> Client.n3.handle(bottom) [label="JSON"]
}
Subgraphs { # Federated Subgraphs
n10: rectangle label:"User Subgraph"
n11: rectangle label:"User Database"
n12: rectangle label:"Product Subgraph"
n13: rectangle label:"Product Database"
n14: rectangle label:"Review Subgraph"
n15: rectangle label:"Review Database"
n10.handle(right) -> n11.handle(left) [label="Query"]
n12.handle(right) -> n13.handle(left) [label="Query"]
n14.handle(right) -> n15.handle(left) [label="Query"]
n11.handle(top) -> Gateway.n8.handle(bottom) [label="User Data"]
n13.handle(top) -> Gateway.n8.handle(bottom) [label="Product Data"]
n15.handle(top) -> Gateway.n8.handle(bottom) [label="Review Data"]
}

为什么需要这个工作流?

A monolithic GraphQL server becomes a deployment bottleneck when multiple teams contribute to the same schema. GraphQL federation allows each team to independently develop, deploy, and scale their own subgraph while the gateway automatically composes them into a single unified API for clients.

工作原理

  1. Step 1: The client sends a single GraphQL query to the Apollo Federation Gateway.
  2. Step 2: The gateway parses the query and builds an execution plan identifying which subgraphs own which fields.
  3. Step 3: Parallel requests are fanned out to User, Product, and Review subgraphs.
  4. Step 4: Each subgraph queries its own database and returns its portion of the response.
  5. Step 5: The gateway stitches all subgraph responses into a single unified GraphQL result.
  6. Step 6: The composed response is returned to the client as if it came from a single API.

替代方案

Schema stitching is an older approach that requires manual configuration. A monolithic GraphQL server is simpler but creates team coupling. REST with API composition achieves similar results without GraphQL. This template shows the federated approach for multi-team GraphQL.

Key Facts

Template NameGraphQL 联邦架构
CategoryArchitecture
Steps6 workflow steps
FormatFlowZap Code (.fz file)

相关模板

微服务 API 网关架构

Architecture

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

微服务服务网格架构

Architecture

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

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

Architecture

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

按业务能力分解微服务架构

Architecture

按业务能力组织的微服务分解架构图:身份认证、产品目录、定价和订单履行,每个都有独立的数据存储和 API。该模板展示如何将单体应用拆分为与业务领域对齐的服务,使用 Backend-for-Frontend (BFF) 模式进行客户端特定的聚合。适合规划领域驱动微服务边界的架构师。

微服务绞杀者模式迁移架构

Architecture

绞杀者模式迁移架构图,展示使用路由层在新旧系统之间分流流量,逐步用新微服务替换遗留单体应用。该模板模拟经过验证的迁移策略,新功能作为微服务构建,遗留端点逐步退役。对于在不进行高风险大爆炸重写的情况下现代化遗留系统的团队至关重要。

微服务服务发现架构

Architecture

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

返回所有模板