Skip to content

Commit c31a7aa

Browse files
committed
Apply feedback
1 parent 2655171 commit c31a7aa

File tree

1 file changed

+101
-76
lines changed

1 file changed

+101
-76
lines changed

src/pages/learn/federation.mdx

Lines changed: 101 additions & 76 deletions
Original file line numberDiff line numberDiff line change
@@ -6,26 +6,37 @@ import { Tabs } from 'nextra/components'
66

77
# GraphQL Federation
88

9-
As applications grow more complex, traditional monolithic approaches often fall short. At scale, monolithic architectures can become cumbersome, brittle, and increasingly hard to test and validate. This has led to a rise in the adoption of new patterns like distributed systems and microservices. In some ways, GraphQL Federation is like microservices for GraphQL – an architectural pattern that has found particular resonance in the GraphQL ecosystem.
10-
11-
GraphQL Federation gained widespread adoption after [Apollo GraphQL introduced Apollo Federation in 2019](https://www.apollographql.com/blog/apollo-federation-f260cf525d21).
12-
Their implementation has become a reference point for the GraphQL community,
13-
helping establish federation as a standard architectural pattern for building a distributed graph in the GraphQL ecosystem.
14-
15-
With more companies and developers seeing the benefits of building a distributed graph with federation, the GraphQL ecosystem is now moving towards standardization of federation patterns.
16-
The GraphQL Foundation's [Composite Schema Working Group](https://github.com/graphql/composite-schemas-wg),
17-
which includes engineers from various organizations across the industry including
18-
Apollo GraphQL, ChilliCream, Graphile, Hasura, Netflix and The Guild,
19-
is actively working on creating an official specification for GraphQL Federation.
20-
This effort aims to standardize how GraphQL services can be composed and executed across distributed systems,
21-
while ensuring room for innovation and different implementations.
9+
As applications grow more complex, traditional monolithic approaches often fall short. At scale,
10+
monolithic architectures can become cumbersome, brittle, and increasingly hard to test and validate.
11+
This has led to a rise in the adoption of new patterns like distributed systems and microservices.
12+
In some ways, GraphQL Federation is like microservices for GraphQL – an architectural pattern that
13+
has found particular resonance in the GraphQL ecosystem.
14+
15+
GraphQL Federation gained widespread adoption after
16+
[Apollo GraphQL introduced Apollo Federation in 2019](https://www.apollographql.com/blog/apollo-federation-f260cf525d21).
17+
Their implementation has become a reference point for the GraphQL community, helping establish
18+
federation as a standard architectural pattern for building a distributed graph in the GraphQL
19+
ecosystem.
20+
21+
With more companies and developers seeing the benefits of building a distributed graph with
22+
federation, the GraphQL ecosystem is now moving towards standardization of federation patterns. The
23+
GraphQL Foundation's
24+
[Composite Schema Working Group](https://github.com/graphql/composite-schemas-wg), which includes
25+
engineers from various organizations across the industry including
26+
[Apollo GraphQL](https://apollographql.com), [ChilliCream](https://chillicream.com/),
27+
[Graphile](https://www.graphile.org/), [Hasura](https://hasura.io/),
28+
[Netflix](https://www.netflix.com/) and [The Guild](https://the-guild.dev), is actively working on
29+
creating
30+
[an official specification for GraphQL Federation](https://github.com/graphql/composite-schemas-spec).
31+
This effort aims to standardize how GraphQL services can be composed and executed across distributed
32+
systems, while ensuring room for innovation and different implementations.
2233

2334
## What is federation?
2435

25-
Architecturally, federation is an approach to organizing and managing distributed systems.
26-
At its core, federation allows autonomous components to work together while maintaining their independence.
27-
Think of it like a federal government system: individual states maintain their sovereignty
28-
while cooperating under a central authority for shared concerns.
36+
Architecturally, federation is an approach to organizing and managing distributed systems. At its
37+
core, federation allows autonomous components to work together while maintaining their independence.
38+
Think of it like a federal government system: individual states maintain their sovereignty while
39+
cooperating under a central authority for shared concerns.
2940

3041
In software architecture, federation enables organizations to:
3142

@@ -35,35 +46,37 @@ In software architecture, federation enables organizations to:
3546
- Enable autonomous development and deployment
3647
- Reduce single points of failure
3748

38-
Think of the "Login with Google" or "Login with Facebook" buttons you see on websites.
39-
This is federation in action: you can use your Google or Facebook account to log into many different websites,
40-
even though each company manages their own login system separately.
49+
Think of the "Login with Google" or "Login with Facebook" buttons you see on websites. This is
50+
federation in action: you can use your Google or Facebook account to log into many different
51+
websites, even though each company manages their own login system separately.
4152

4253
## What Is Federated GraphQL?
4354

44-
GraphQL Federation applies those principles to GraphQL APIs.
45-
It enables organizations to build a unified GraphQL schema from multiple independent services (most often called subgraphs),
46-
each responsible for its portion of the application's data graph.
55+
GraphQL Federation applies those principles to GraphQL APIs. It enables organizations to build a
56+
unified GraphQL schema from multiple independent services (most often called subgraphs), each
57+
responsible for its portion of the application's data graph.
4758

48-
Consider an e-commerce platform: You might have separate teams managing products, user accounts, and order processing. With GraphQL Federation, each team can:
59+
Consider an e-commerce platform: You might have separate teams managing products, user accounts, and
60+
order processing. With GraphQL Federation, each team can:
4961

5062
- Define their own GraphQL schema
5163
- Deploy and scale their service independently
5264
- Contribute to a unified GraphQL API without tight coupling
5365
- Maintain ownership of their domain-specific logic
5466

55-
The magic happens through a federated gateway that acts as the central coordinator, composing these separate schemas into a unified schema that clients can query.
67+
The magic happens through a federated gateway that acts as the central coordinator, composing these
68+
separate schemas into a unified schema that clients can query.
5669

5770
## How Federation Works in GraphQL
5871

5972
The federation process involves several key components:
6073

6174
- **Subgraphs**: Individual services that define their own GraphQL schemas and resolvers
6275
- **Gateway**: A specialized service that sits between clients and your federated services
63-
- **Schema composition**: The process of merging schemas while resolving references between them, often handled by schema registries.
76+
- **Schema composition**: The process of merging schemas while resolving references between them,
77+
often handled by schema registries.
6478

65-
<Tabs items={['Products subgraph', 'Orders subgraph', 'Users subgraph']}>
66-
<Tabs.Tab>
79+
<Tabs items={['Products subgraph', 'Orders subgraph', 'Users subgraph']}> <Tabs.Tab>
6780

6881
```graphql
6982
type Product @key(fields: "id") {
@@ -74,8 +87,7 @@ type Product @key(fields: "id") {
7487
}
7588
```
7689

77-
</Tabs.Tab>
78-
<Tabs.Tab>
90+
</Tabs.Tab> <Tabs.Tab>
7991

8092
```graphql
8193
type Order @key(fields: "id") {
@@ -89,8 +101,8 @@ type Product {
89101
}
90102
```
91103

92-
</Tabs.Tab>
93-
<Tabs.Tab>
104+
</Tabs.Tab> <Tabs.Tab>
105+
94106
```graphql
95107
type Query {
96108
user(id: ID!): User
@@ -108,16 +120,18 @@ type Order {
108120
}
109121
```
110122

111-
</Tabs.Tab>
112-
</Tabs>
123+
</Tabs.Tab> </Tabs>
113124

114125
### Schema Composition
115126

116-
Let's break down schema composition in GraphQL federation with more detail and examples.
117-
Schema composition is the process where multiple subgraph schemas are combined into one unified schema.
118-
It's more complex than simply merging schemas together, though, because it needs to handle relationships, detect incompatibilities, and ensure types are properly connected across services and subgraphs.
127+
Let's break down schema composition in GraphQL federation with more detail and examples. Schema
128+
composition is the process where multiple subgraph schemas are combined into one unified schema.
129+
It's more complex than simply merging schemas together, though, because it needs to handle
130+
relationships, detect incompatibilities, and ensure types are properly connected across services and
131+
subgraphs.
119132

120-
Based on the examples we provided before, here's the unified schema GraphQL clients will see and can query:
133+
Based on the examples we provided before, here's the unified schema GraphQL clients will see and can
134+
query:
121135

122136
```graphql
123137
type Query {
@@ -145,14 +159,14 @@ type Product {
145159
}
146160
```
147161

148-
This unified schema combines types and fields from all three subgraphs (Users, Orders, and Products), allowing clients to seamlessly query across these domains.
162+
This unified schema combines types and fields from all three subgraphs (Users, Orders, and
163+
Products), allowing clients to seamlessly query across these domains.
149164

150165
### Gateway
151166

152-
The federation gateway is the entry point to your distributed data graph.
153-
It presents a unified GraphQL endpoint to clients
154-
and handles the complexity of routing queries to the appropriate subgraphs and assembling the results,
155-
and often provides caching and performance optimizations.
167+
The federation gateway is the entry point to your distributed data graph. It presents a unified
168+
GraphQL endpoint to clients and handles the complexity of routing queries to the appropriate
169+
subgraphs and assembling the results, and often provides caching and performance optimizations.
156170

157171
```mermaid
158172
graph TD
@@ -188,62 +202,73 @@ query {
188202
}
189203
```
190204

191-
The gateway will route parts of the query to the appropriate subgraphs, collect the results,
192-
and assemble them into a single response that the client can consume.
205+
The gateway will route parts of the query to the appropriate subgraphs, collect the results, and
206+
assemble them into a single response that the client can consume.
193207

194208
## Benefits of GraphQL Federation
195209

196210
### Domain-Driven Development
197211

198-
Teams can work independently on their services while contributing to a cohesive API.
199-
This autonomy accelerates development and reduces coordination overhead.
212+
Teams can work independently on their services while contributing to a cohesive API. This autonomy
213+
accelerates development and reduces coordination overhead.
200214

201215
### Service Integrity Protection
202216

203-
The schema composition step verifies integration between services
204-
by ensuring that changes in individual subgraphs
205-
do not conflict with other subgraphs.
217+
The schema composition step verifies integration between services by ensuring that changes in
218+
individual subgraphs do not conflict with other subgraphs.
206219

207220
### Scalability and Performance
208221

209-
Subgraphs and services can be scaled independently based on their specific requirements.
210-
The product catalog might need different scaling characteristics than the order processing system.
222+
Subgraphs and services can be scaled independently based on their specific requirements. The product
223+
catalog might need different scaling characteristics than the order processing system.
211224

212225
### Single, Unified API
213226

214227
Thanks to GraphQL, clients get a single endpoint with unified schema spanning multiple subgraphs.
215-
The complexity of distributed systems is hidden.
216-
The gateway ensures every query reaches its destination and returns with the right data.
228+
The complexity of distributed systems is hidden. The gateway ensures every query reaches its
229+
destination and returns with the right data.
217230

218-
## Federation vs. Monolithic Architecture
231+
## Is GraphQL Federation Right for You?
219232

220-
While monolithic GraphQL APIs have their place, federated architectures offer several advantages for larger applications:
233+
GraphQL Federation aligns naturally with Domain Driven Design (DDD) principles by allowing teams to
234+
maintain clear boundaries around their domains, while maintaining explicit integration points
235+
through the GraphQL schema. It is particularly valuable for organizations where multiple teams need
236+
to work independently on different parts of the GraphQL API, with the flexibility to use different
237+
technologies and programming languages.
221238

222-
| **Aspect** | **Monolithic GraphQL** | **Federated GraphQL** |
223-
| ----------------- | --------------------------------- | ----------------------------- |
224-
| Development Speed | Initially faster | Better for long-term velocity |
225-
| Team Coordination | Requires significant coordination | Enables independence |
226-
| Deployment | All-or-nothing | Independent deployments |
227-
| Scaling | Entire system scales together | Independent scaling |
239+
However, implementing Federation requires substantial infrastructure support, including a dedicated
240+
team to manage the gateway, schema registry, to help connect subgraphs to the federated API and guide
241+
teams on best practices.
228242

229-
## Real-World Implementations
243+
Before adopting Federation, it's crucial to consider whether your organization truly needs this
244+
level of complexity.
230245

231-
GraphQL Federation is adopted by tech giants such as
232-
[Netlifx](https://netflixtechblog.com/how-netflix-scales-its-api-with-graphql-federation-part-1-ae3557c187e2),
246+
Meta (formerly Facebook), [where GraphQL was created](/blog/2015-09-14-graphql/), has continued to
247+
use a monolithic GraphQL API since 2012. However, companies like
248+
[Netflix](https://netflixtechblog.com/how-netflix-scales-its-api-with-graphql-federation-part-1-ae3557c187e2),
233249
[Expedia Group](https://youtu.be/kpeVT7J6Bsw?si=srGWsoxf3kTmneTu&t=79),
234250
[Volvo](https://www.apollographql.com/blog/volvo-cars-drives-into-the-future-of-online-car-shopping-with-the-supergraph),
235-
and [Booking](https://youtu.be/2KsP_x50tGk?si=mu-MOG-xZQSDNDjh&t=478).
251+
and [Booking](https://youtu.be/2KsP_x50tGk?si=mu-MOG-xZQSDNDjh&t=478) have adopted Federation to
252+
better align with their organizational structures and microservices architecture.
236253

237-
Many industry leaders successfully use GraphQL federation at scale, proving that federation works reliably for large-scale production applications.
254+
As you see, many industry leaders successfully federated their GraphQL APIs, proving that it works
255+
reliably for large-scale production applications.
238256

239257
## Getting Started with GraphQL Federation
240258

241-
To implement GraphQL federation, organizations should:
242-
243-
1. **Identify Service Boundaries**: Define clear boundaries between different domains in your application
244-
2. **Design Schemas**: Create schemas that reflect these boundaries while considering how they'll interact
245-
3. **Implement Subgraphs**: Build individual services that implement their portion of the schema
246-
4. **Set Up a federated Gateway**: Deploy a federation gateway to compose and serve the unified schema
247-
5. **Monitor and Optimize**: Implement monitoring and continuously optimize query performance
248-
249-
Organizations can gradually migrate from a monolithic to federated GraphQL implementation, one service at a time.
259+
If you're considering adopting GraphQL Federation, here are some steps to get started:
260+
261+
1. **Identify Service Boundaries**: Define clear boundaries between different domains in your
262+
application
263+
2. [**Design Schemas**](/learn/schema/ 'Learn about the different elements of the GraphQL type system'):
264+
Create schemas that reflect these boundaries while considering how they'll interact
265+
3. [**Implement Subgraphs**](/community/tools-and-libraries/?tags=server 'Discover a list of GraphQL servers in our Tools and Libraries page'):
266+
Build individual services that implement their portion of the schema
267+
4. [**Set Up a Gateway**](/community/tools-and-libraries/?tags=gateways-supergraphs 'Discover a list of GraphQL gateways in our Tools and Libraries page'):
268+
Deploy a federation gateway to compose and serve the unified schema
269+
5. [**Use a Schema Registry**](/community/tools-and-libraries/?tags=schema-registry 'Discover a list of GraphQL schema registries in our Tools and Libraries page'):
270+
Manage schema composition and validation to ensure integrity across subgraphs
271+
272+
When migrating from a monolithic GraphQL API to Federation, the simplest starting point is to treat
273+
your existing schema as your first subgraph. From there, you can follow the steps above to gradually
274+
decompose your schema into smaller pieces.

0 commit comments

Comments
 (0)