GraphQL Federation, the missing
piece of microservices
dtuan@alpha-sense.com / dt@luc.vc
https://www.alpha-sense.com/careers/helsinki/
Jobs are opening
1
AlphaSense is a
AI-Powered Search
leading all-in-one market intelligence platform
headquarters in US
recognized by Forbes
as a top 50 AI company in
2023
🇺🇸 🇫🇮 🇮🇳 🇸🇬 🇩🇪 🏴󠁧󠁢󠁥󠁮󠁧󠁿
API Team
GraphQL Service Development &
Maintenance
GraphQL Federation Knowledge
Leaders & Educators
Exposing GraphQL APIs to
External Clients
https://www.alpha-sense.com/
https://www.alpha-
sense.com/careers/helsinki/
4
Microservices are domain-based
monolith service services
5
Monolith
async function runQuery() {
try {
const client = await
pool.connect();
const result: QueryResult =
await client.query('SELECT *
FROM your_table_name');
client.release();
} catch (error) {
console.error('Error
executing query:', error);
}
}
Presentation Layer Logic Layer Data Layer
Database
6
Microservices
async function runQuery() {
try {
const client = await pool.connect();
const result: QueryResult = await
client.query('SELECT * FROM
your_table_name');
client.release();
} catch (error) {
console.error('Error executing query:',
error);
}
}
Database
APIs
User
async function runQuery() {
try {
const client = await pool.connect();
const result: QueryResult = await
client.query('SELECT * FROM
your_table_name');
client.release();
} catch (error) {
console.error('Error executing query:',
error);
}
}
Database
APIs
Search
async function runQuery() {
try {
const client = await pool.connect();
const result: QueryResult = await
client.query('SELECT * FROM
your_table_name');
client.release();
} catch (error) {
console.error('Error executing query:',
error);
}
}
Database
APIs
Watchlist
User team
Search team
Watchlist team
7
Consider following example
Client wants to fetch user together with documents
and their watchlists
USER Service DOCUMENT Service WATCHLIST Service
GET /user/123
GET /documents?user_id=123
GET /watchlists?user_id=123
with RESTful API
8
with GraphQL
USER Service
DOCUMENT Service
WATCHLIST Service
GraphQL Server
GraphQL Gateway
GraphQL Gateway
GraphQL Server
GraphQL simplifies data retrieval by allowing clients to fetch
information from multiple services using a single query.
With GraphQL, you can create a unified data responsecombining data from different
sources, making it much easier for clients to consume.
10
REST APIs typically have multiple endpoints for retrieving data from the server, while
GraphQLhas a multiple single endpointto which queries are sent.
Benefits
GraphQLhelps avoidthe issues of 'over-fetching' (retrieving too much data) and 'under-
fetching' (retrieving too little data) that often occur in REST APIs."
12
What is
GraphQL Federation?
13
Normal GraphQL Server?
USER Service
DOCUMENT Service
WATCHLIST Service
GraphQL Server
All the graphql
will be defined
in here
14
What is GraphQL Federation?
USER Service
DOCUMENT Service
WATCHLIST Service
GraphQL Gateway
Combine multipleGraphQL SubGraphs into
a single, federatedSuperGraph
This federated graphenables clients to interact
with multiple APIs through a single
request.
15
Unified GraphQL API
It allows the combination of multiple GraphQL APIs into a single, federated graph. This means clients can interact with multiple APIs through just
one request, streamlining the request and response cycle
Other benefits
Preserving Client Simplicity and Performance
It eliminates the need for multiple requests to different non-federated GraphQL APIs, offering the advantage of fetching all necessary data in a single request, which is
particularly beneficial in scenarios where multiple teams develop APIs independently
Simplified Schema Design at Scale
Unlike other approaches that may complicate the federated schema, GraphQL Federation allows clients to interact with the federated schema as if it were a single,
monolithic structure. This simplifies both frontend and backend interactions
Single API Maintenance
Each team contributes to the federated GraphQL schema, working independently without the need to maintain multiple API layers. This approach centralizes quality
control and updates to a single platform team
16
How to develop with GraphQL Federation?
GraphQL Gateway
USER Service
WATCHLIST Service
DOCUMENT Service
Git repositories CI/CD Pipeline
SuperGraph
Builder
17
SuperGraph builder
18
GraphQL Cosmo
Thanks!
Luc <dt@luc.vc>

GraphQL Federation, the missing piece of microservices

  • 1.
    GraphQL Federation, themissing piece of microservices dtuan@alpha-sense.com / dt@luc.vc https://www.alpha-sense.com/careers/helsinki/ Jobs are opening
  • 2.
    1 AlphaSense is a AI-PoweredSearch leading all-in-one market intelligence platform headquarters in US recognized by Forbes as a top 50 AI company in 2023 🇺🇸 🇫🇮 🇮🇳 🇸🇬 🇩🇪 🏴󠁧󠁢󠁥󠁮󠁧󠁿
  • 3.
    API Team GraphQL ServiceDevelopment & Maintenance GraphQL Federation Knowledge Leaders & Educators Exposing GraphQL APIs to External Clients https://www.alpha-sense.com/ https://www.alpha- sense.com/careers/helsinki/
  • 4.
  • 5.
    5 Monolith async function runQuery(){ try { const client = await pool.connect(); const result: QueryResult = await client.query('SELECT * FROM your_table_name'); client.release(); } catch (error) { console.error('Error executing query:', error); } } Presentation Layer Logic Layer Data Layer Database
  • 6.
    6 Microservices async function runQuery(){ try { const client = await pool.connect(); const result: QueryResult = await client.query('SELECT * FROM your_table_name'); client.release(); } catch (error) { console.error('Error executing query:', error); } } Database APIs User async function runQuery() { try { const client = await pool.connect(); const result: QueryResult = await client.query('SELECT * FROM your_table_name'); client.release(); } catch (error) { console.error('Error executing query:', error); } } Database APIs Search async function runQuery() { try { const client = await pool.connect(); const result: QueryResult = await client.query('SELECT * FROM your_table_name'); client.release(); } catch (error) { console.error('Error executing query:', error); } } Database APIs Watchlist User team Search team Watchlist team
  • 7.
    7 Consider following example Clientwants to fetch user together with documents and their watchlists USER Service DOCUMENT Service WATCHLIST Service GET /user/123 GET /documents?user_id=123 GET /watchlists?user_id=123 with RESTful API
  • 8.
    8 with GraphQL USER Service DOCUMENTService WATCHLIST Service GraphQL Server GraphQL Gateway GraphQL Gateway GraphQL Server GraphQL simplifies data retrieval by allowing clients to fetch information from multiple services using a single query. With GraphQL, you can create a unified data responsecombining data from different sources, making it much easier for clients to consume.
  • 9.
    10 REST APIs typicallyhave multiple endpoints for retrieving data from the server, while GraphQLhas a multiple single endpointto which queries are sent. Benefits GraphQLhelps avoidthe issues of 'over-fetching' (retrieving too much data) and 'under- fetching' (retrieving too little data) that often occur in REST APIs."
  • 10.
  • 11.
    13 Normal GraphQL Server? USERService DOCUMENT Service WATCHLIST Service GraphQL Server All the graphql will be defined in here
  • 12.
    14 What is GraphQLFederation? USER Service DOCUMENT Service WATCHLIST Service GraphQL Gateway Combine multipleGraphQL SubGraphs into a single, federatedSuperGraph This federated graphenables clients to interact with multiple APIs through a single request.
  • 13.
    15 Unified GraphQL API Itallows the combination of multiple GraphQL APIs into a single, federated graph. This means clients can interact with multiple APIs through just one request, streamlining the request and response cycle Other benefits Preserving Client Simplicity and Performance It eliminates the need for multiple requests to different non-federated GraphQL APIs, offering the advantage of fetching all necessary data in a single request, which is particularly beneficial in scenarios where multiple teams develop APIs independently Simplified Schema Design at Scale Unlike other approaches that may complicate the federated schema, GraphQL Federation allows clients to interact with the federated schema as if it were a single, monolithic structure. This simplifies both frontend and backend interactions Single API Maintenance Each team contributes to the federated GraphQL schema, working independently without the need to maintain multiple API layers. This approach centralizes quality control and updates to a single platform team
  • 14.
    16 How to developwith GraphQL Federation? GraphQL Gateway USER Service WATCHLIST Service DOCUMENT Service Git repositories CI/CD Pipeline SuperGraph Builder
  • 15.
  • 16.
  • 17.