GraphQL Federation with Apollo: Scaling Graphs
Microservices are great, but managing their APIs can be a nightmare. Learn how Federation unites them into a single, cohesive graph.
Introduction
In a monolithic architecture, a single GraphQL server handles everything. But as your team grows, this becomes a bottleneck. You split into microservices, but now your client has to query five different endpoints.
GraphQL Federation solves this. It allows you to build a distributed graph where each service (subgraph) owns a piece of the data, but they are all exposed via a single Gateway.
💡 Why This Matters: You get the organizational benefits of microservices with the simplicity of a monolithic API for the frontend.
Key Concepts
Building a Subgraph
Let's look at a Java (Spring Boot) subgraph using `dgs-framework` (Netflix's DGS).
type User @key(fields: "id") {
id: ID!
username: String
email: String
}
type Query {
users: [User]
}@DgsComponent
public class UserFetcher {
@DgsEntityFetcher(name = "User")
public User user(Map<String, Object> values) {
String id = (String) values.get("id");
return userService.findById(id);
}
}
The Gateway (Apollo Router)
The gateway sits in front of your subgraphs. In 2025, the standard is the Apollo Router, a high-performance Rust binary.
federation_version: 2.0
subgraphs:
users:
routing_url: http://users-service:8080/graphql
schema:
file: ./subgraphs/users.graphql
reviews:
routing_url: http://reviews-service:4000/graphql
schema:
file: ./subgraphs/reviews.graphqlSecurity Considerations
Centralizing access points introduces risks.
🔒 Authentication
Authenticate at the Gateway. Pass user context (e.g., headers) to subgraphs.
🔒 Query Depth
Limit query depth to prevent DoS attacks (nested queries).
🔒 Introspection
Disable introspection in production to hide schema details.
🔒 Private Subgraphs
Ensure subgraphs are not directly accessible from the public internet.
✅ Federation Checklist
Ready to federate?
Test Your Queries
Use our tools to format and validate your GraphQL queries.
Related Topics
Conclusion
GraphQL Federation is the architecture of choice for enterprise graphs. It enables teams to work independently while presenting a unified face to the client.
While it adds operational complexity (maintaining a Gateway), the benefits in developer velocity and client simplicity are unmatched for large-scale systems.