Inferensys

Glossary

GraphQL Federation

GraphQL Federation is an architecture pattern that composes a single, unified GraphQL API (a supergraph) from multiple independent backend services (subgraphs), managed by a federation gateway.
Architect reviewing LLM integration architecture on laptop, system diagrams visible, modern technical office setup.
EXTERNAL SYSTEM CONNECTOR

What is GraphQL Federation?

GraphQL Federation is an architectural pattern for composing a single, unified GraphQL API (a supergraph) from multiple, independently deployed GraphQL services (subgraphs).

GraphQL Federation is a backend architecture pattern that enables a unified GraphQL API (called a supergraph) to be composed from multiple, independently managed GraphQL services (called subgraphs). A federation gateway (or router) receives client queries, intelligently plans their execution across the relevant subgraphs, and stitches the results into a single response. This allows large organizations to scale their GraphQL implementation across separate teams and technology stacks while presenting a single, cohesive schema to consumers.

The pattern is defined by a federation specification that subgraphs follow, primarily using directives like @key to designate an entity's primary fields and @requires and @provides to express dependencies between services. This enables schema stitching at runtime without a centralized build process. Federation contrasts with GraphQL schema stitching, which often requires manual coordination, by providing a declarative, contract-first approach for building a distributed GraphQL architecture.

ARCHITECTURE PATTERN

Core Components of GraphQL Federation

GraphQL Federation is an architectural pattern for composing a single, unified GraphQL API (a supergraph) from multiple, independently deployable GraphQL services (subgraphs). This enables teams to own their domain data while contributing to a cohesive enterprise schema.

01

Subgraph

A subgraph is an independently deployable GraphQL service that defines a portion of the overall domain. It exposes its own GraphQL schema and is responsible for resolving the data for the types and fields it owns. Key characteristics include:

  • Ownership: A subgraph owns specific types (e.g., a Product subgraph owns the Product type).
  • Schema Definition: It uses special federation directives (like @key) to declare how its types can be referenced and extended by other subgraphs.
  • Resolver Implementation: Contains the business logic and data-fetching code for its portion of the graph.
02

Supergraph Schema

The supergraph schema is the unified, composed GraphQL API schema that clients interact with. It is generated by a federation gateway by intelligently merging all subgraph schemas. Its composition involves:

  • Schema Stitching: The gateway combines type definitions, merges duplicate types, and connects them via @key references.
  • Query Planning: The gateway analyzes incoming client queries and generates an execution plan that determines which subgraphs to call and in what order.
  • Single Endpoint: Clients send queries to a single supergraph endpoint, unaware of the underlying service decomposition.
03

Federation Gateway / Router

The gateway (or router) is the runtime component that sits between clients and the subgraphs. It is responsible for query execution, routing, and composition. Its core duties are:

  • Query Parsing & Validation: Accepts and validates incoming GraphQL operations against the supergraph schema.
  • Query Planning: Creates an optimized execution plan, breaking a single client query into multiple sub-queries for different subgraphs.
  • Request Routing: Delegates these sub-queries to the correct subgraph services.
  • Response Composition: Aggregates the results from all subgraphs and returns a single, unified response to the client. Apollo Router and WunderGraph are common implementations.
04

Federation Directives

Federation directives are custom GraphQL schema directives used within subgraph schemas to provide metadata for composition. They are the declarative language of federation.

  • @key: Defines the primary key fields for an entity, enabling other subgraphs to reference it. Example: type Product @key(fields: "id") { id: ID! name: String }
  • @extends: Used to indicate that a type is defined in another subgraph but is being extended with new fields in the current subgraph.
  • @external: Marks a field as being defined in another subgraph; it's used in conjunction with @requires and @provides.
  • @requires: Specifies that a field in this subgraph requires data from another subgraph to resolve.
  • @provides: Specifies that a subgraph, while resolving a field, can guarantee to return certain fields defined in another subgraph.
05

Entity

An entity is a GraphQL object type that can be resolved across multiple subgraphs. It is the central concept for sharing and extending types in federation.

  • Definition: Any type annotated with the @key directive is an entity.
  • Reference Resolution: When a subgraph returns a reference to an entity (e.g., { __typename: "Product", id: "prod_1" }), the gateway uses this representation to fetch the remaining fields from the subgraph that owns that entity.
  • Distributed Ownership: Different subgraphs can contribute different fields to the same entity. For example, the Product entity might have id and name from a Catalog subgraph, and inventoryCount from an Inventory subgraph.
06

Query Plan

A query plan is the internal execution blueprint created by the federation gateway. It is the result of query planning and dictates how a client's single query is decomposed.

  • Operation: The gateway parses the client query and matches each field against the supergraph schema to see which subgraph can resolve it.
  • Decomposition: The query is split into a series of dependent fetch nodes.
  • Optimization: The plan minimizes sequential calls and batches requests where possible.
  • Execution: The gateway executes the fetch nodes in order, passing data from one subgraph's response as variables to the next, finally composing the final result. This process is transparent to the client.
EXTERNAL SYSTEM CONNECTORS

How GraphQL Federation Works

GraphQL Federation is an architecture pattern for composing a unified GraphQL API (a supergraph) from multiple independent GraphQL microservices (subgraphs).

GraphQL Federation is an architectural pattern that enables a single, unified GraphQL API, called a supergraph, to be composed from multiple independent GraphQL services, known as subgraphs. A federation gateway (or router) manages this composition, receiving client queries and intelligently delegating portions of the query to the appropriate backend subgraph services. This allows different teams to own and evolve their domain-specific subgraphs autonomously while presenting a cohesive data graph to consumers.

The pattern relies on a federation specification that defines how subgraphs declare their schema contributions and resolve references to entities owned by other services. Key mechanisms include entity keys for unique identification across subgraphs and reference resolvers that allow the gateway to fetch related data from other services. This stands in contrast to schema stitching, as federation pushes query planning and execution logic to a dedicated gateway, providing a more declarative and managed approach to schema composition for large-scale, distributed GraphQL implementations.

GRAPHQL FEDERATION

Frequently Asked Questions

GraphQL Federation is an architectural pattern for composing a unified GraphQL API from multiple independent backend services. This FAQ addresses its core concepts, implementation, and role in AI agent integration.

GraphQL Federation is an architecture pattern that enables multiple independent GraphQL services (called subgraphs) to be combined into a single, unified supergraph API, managed by a federation gateway (or router). It works by allowing each subgraph to define a portion of the overall schema and declare which types and fields it is responsible for. The gateway composes these partial schemas, intelligently routes incoming queries to the correct services, and merges the results into a single response for the client. This allows a client to query data from multiple backend services in one request without knowing the underlying service boundaries.

Key components include:

  • Subgraph: An independent GraphQL service that defines a fragment of the overall schema.
  • Supergraph Schema: The composed, unified schema generated from all subgraph schemas.
  • Federation Gateway/Router: The runtime component that receives client queries, plans their execution across subgraphs, and assembles the final result.
  • @key Directive: The primary directive a subgraph uses to mark a type as an entity and specify its primary key fields, enabling other subgraphs to reference and extend it.
Prasad Kumkar

About the author

Prasad Kumkar

CEO & MD, Inference Systems

Prasad Kumkar is the CEO & MD of Inference Systems and writes about AI systems architecture, LLM infrastructure, model serving, evaluation, and production deployment. Over 5+ years, he has worked across computer vision models, L5 autonomous vehicle systems, and LLM research, with a focus on taking complex AI ideas into real-world engineering systems.

His work and writing cover AI systems, large language models, AI agents, multimodal systems, autonomous systems, inference optimization, RAG, evaluation, and production AI engineering.