GraphQL Federation: Subgraphs, Routing, and Trade-offs

Learn how GraphQL federation composes subgraphs, routes operations, and affects service ownership, query planning, latency, failure handling, and authorization.

published: reading time: 4 min read author: GeekWorkBench
Quick Summary

Learn how GraphQL federation composes subgraphs, routes operations, and affects service ownership, query planning, latency, failure handling, and authorization.

GraphQL Federation: Subgraphs, Routing, and Trade-offs

GraphQL federation lets multiple services contribute parts of a client-facing schema. Each service publishes a subgraph schema describing the types and fields it can resolve. A composition step combines those schemas, and a router uses the resulting metadata to send operations to the relevant subgraphs. Apollo’s federation overview describes this model; other federation implementations may have different tooling and conventions.

Federation can support separate domain ownership, but it adds schema coordination and cross-service work to requests. Any performance gain depends on the workload and the router’s query plan. For the broader comparison, see GraphQL vs REST.

How the Pieces Fit

Teams define subgraph schemas around the data they own. Composition checks whether those schemas can form a valid supergraph. The router exposes an API schema to clients and plans operations across subgraphs. The composition documentation explains how Apollo combines definitions and reports conflicts before publishing a composed schema.

For example, a client may request an order and the customer who placed it. An Orders subgraph resolves the order; a Customers subgraph resolves customer details. The router can issue work to both services and connect the results. Entity keys or equivalent references help a router continue resolving an object across subgraphs.

type Order @key(fields: "id") {
  id: ID!
  customerId: ID!
}

The syntax and directives depend on the federation implementation. In Apollo Federation, @key marks an entity that can be identified across subgraphs.

What Changes at Runtime

A request that touches one subgraph may behave like a request to one GraphQL service. A request that crosses several subgraphs adds network hops, service dependencies, and more places where latency or partial failure can occur. Query planning also matters: the router may need one subgraph’s result before it can ask another for related fields. Inspect a representative plan and trace the downstream calls when evaluating a schema; Apollo documents the structure in its query plans guide.

Service boundaries still matter: a composed API does not create a database-wide transaction or remove network failures. Each subgraph must enforce authorization for the data it owns. Define how errors and unavailable subgraphs appear to clients, and avoid returning fields a caller could not access directly.

When Federation Fits

Federation is worth evaluating when services have durable domain boundaries, teams can own and evolve their schemas, and clients benefit from one composed graph. Before adopting it, establish a review and composition workflow, assign ownership for shared types, monitor cross-subgraph latency, and make a plan for schema changes that affect multiple teams.

Federation adds coordination when one team owns a small API or services lack clear boundaries. Schema stitching and a conventional gateway are other options; choose based on the ownership model and runtime behavior you need.

Adoption Checklist

  • Name an owner for each subgraph and for shared types or fields.
  • Run composition checks in the schema-change workflow before publishing.
  • Measure query plans and downstream calls for common client operations.
  • Set timeouts, retries, and partial-failure behavior for subgraph calls.
  • Keep authorization in the service or trusted data boundary that owns each resource.
  • Track schema changes, deprecations, and client usage before removing fields.

For access-control fundamentals, read API authentication vs authorization. Federation changes how requests are routed; it does not replace object-level permission checks.

Conclusion

Federation composes service-owned schemas behind a router. Its value depends on clear ownership and a measured need for a shared graph; its costs show up in composition work, query planning, cross-service latency, failure handling, and distributed authorization.

Category

Related Posts

Amazon Architecture: History and Service Design

Separate documented Amazon and AWS milestones from popular retellings, then apply the lesson about service boundaries to a current request flow.

#microservices #amazon #architecture

Asynchronous Communication: From Outbox to Consumer

Choose when to use asynchronous messaging and follow an order event through an outbox, delivery, idempotency, retries, dead-letter handling, and monitoring.

#microservices #asynchronous #event-driven

Client-Side Discovery in Microservices

Explore client-side service discovery patterns, how clients directly query the service registry, and when this approach works best.

#microservices #client-side-discovery #service-discovery