Skip to content
Santekno.com | Tech Tutorials and Trends
EN
📖 0%
06 Sep 2025 · 5 min read ·Article 68 / 125
Go

68 Gateway Server and Remote Schema Stitching

IH
Ihsan Arif
Writer at Santekno · Backend Engineer

68 Gateway Server and Remote Schema Stitching: A Futuristic Step for the Grafana API

Modern APIs demand flexibility, scalability, and seamless integration. As microservices architectures grow ever more popular, a new challenge emerges: how do you integrate multiple services, each with its own GraphQL schema? This is exactly where the concepts of a gateway server and remote schema stitching become crucial. In this article, I’ll cover the concept of the 68 Gateway Server, explain why Remote Schema Stitching matters, and show how to implement it, complete with code examples, flow diagrams, and a simple simulation.


What Is the 68 Gateway Server?

The term “68 Gateway Server” refers to a gateway architecture capable of connecting up to 68 different schema sources—whether monolithic or microservice—into a single, seamlessly integrated GraphQL API. While the number 68 is just a metaphor, the underlying concept is to provide one front door for many services running behind the scenes.

Its main benefits include:

  • Single entry point: One GraphQL endpoint for all services.
  • Centralized authentication & authorization: A single layer for authentication and authorization.
  • Schema federation & composition: Dynamically combine many GraphQL schemas.

Understanding Remote Schema Stitching

Schema stitching is a technique for merging several separate GraphQL schemas into one large schema. With remote schema stitching, this process is performed dynamically against external (remote) schema sources.

Example scenario:

  • Service A (User Service): Manages user data.
  • Service B (Product Service): Manages product data.

With schema stitching, clients can query both user data and product data through a single endpoint.


The Difference Between Schema Stitching and Federation

Before diving into the implementation, you need to understand the difference between the two well-known approaches in GraphQL gateways:

Schema StitchingFederation
Merges schemas explicitly (manual mapping and links between types).Each service defines “federation directives” for automatic joins at the gateway.
Supports any GraphQL serverTypically only supported via Apollo Federation syntax
More flexible and customizableAutomatic and easier to scale
Great for custom use cases and external integrationsIdeal for large microservices with separate teams

Architecture Diagram with Schema Stitching

Let’s look at a flow diagram of how the 68 Gateway Server performs schema stitching:

MERMAID
graph TD
    subgraph Gateway Server
        GWS(Gateway)
    end
    subgraph Microservices
        SVC1[User Service]
        SVC2[Product Service]
        SVC3[Inventory Service]
        SVCx[Service 68...]
    end
    Client --> GWS
    GWS --> SVC1
    GWS --> SVC2
    GWS --> SVC3
    GWS --> SVCx
In this architecture, the Gateway becomes the single interface to many backend services.


Implementation: Remote Schema Stitching with Node.js & @graphql-tools

To make remote stitching possible, we’ll use the highly powerful @graphql-tools/stitch package.

Example: Stitching the User and Product Services

Step 1: Prepare the Remote Executable Schemas

Assume the two main services are already online at their respective endpoints.

  • User Service: http://localhost:4001/graphql
  • Product Service: http://localhost:4002/graphql

Step 2: Gateway Code (server.js)

js
 1const { stitchSchemas } = require('@graphql-tools/stitch');
 2const { makeRemoteExecutableSchema } = require('@graphql-tools/wrap');
 3const { introspectSchema } = require('@graphql-tools/wrap');
 4const { ApolloServer } = require('apollo-server');
 5const { HttpLink } = require('apollo-link-http');
 6const fetch = require('node-fetch');
 7
 8async function buildGatewaySchema() {
 9    // Create link to remote services
10    const userLink = new HttpLink({ uri: 'http://localhost:4001/graphql', fetch });
11    const productLink = new HttpLink({ uri: 'http://localhost:4002/graphql', fetch });
12
13    // Introspect and wrap remote schemas
14    const userSchema = makeRemoteExecutableSchema({
15        schema: await introspectSchema(userLink),
16        link: userLink,
17    });
18
19    const productSchema = makeRemoteExecutableSchema({
20        schema: await introspectSchema(productLink),
21        link: productLink,
22    });
23
24    // Stitch schemas with custom resolvers if needed
25    return stitchSchemas({
26        subschemas: [
27            { schema: userSchema },
28            { schema: productSchema }
29        ],
30        // Optionally, define merge logic or resolvers here
31    });
32}
33
34async function startServer() {
35    const schema = await buildGatewaySchema();
36
37    const server = new ApolloServer({ schema });
38
39    server.listen(4000).then(({ url }) => {
40        console.log(`🚀 Gateway ready at ${url}`);
41    });
42}
43startServer();

With this code, the server accepts requests on a single endpoint (localhost:4000) while the data is fetched from two different services.


Simulating a Gateway Query

You can run a combined query like the following against the gateway:

graphql
 1query {
 2  userById(id: "u123") {
 3    id
 4    name
 5  }
 6  products {
 7    id
 8    name
 9    stock
10  }
11}

The gateway forwards the query to each service, collects the results, and returns them to the client as if all the data came from a single, integrated schema.


Managing Scale: What If You Have 68 Services?

In reality, in the enterprise world, you can have a great many services. The code above is already scalable for adding new services:

js
 1const services = [
 2  'http://localhost:4001/graphql',
 3  'http://localhost:4002/graphql',
 4  // ... up to 68 endpoints
 5];
 6const schemas = [];
 7for (const uri of services) {
 8    const link = new HttpLink({ uri, fetch });
 9    const schema = await makeRemoteExecutableSchema({
10        schema: await introspectSchema(link),
11        link
12    });
13    schemas.push({ schema });
14}
15return stitchSchemas({ subschemas: schemas });

Note: Tune your connections, memory, and timeouts to avoid overfetching.


Best Practices and Challenges

ChallengeSolution
Schema overlap / naming conflicts between servicesUse namespaces or prefixes on types and fields
SecurityImplement auth at the gateway/data-source layer
Performance (over-fetch/latency)Use batching & caching (e.g., dataloader )
Deployment & observabilityLogging, tracing, and centralized error handling
Schema versioningPatterns: deprecate fields, separate services, versioning

Conclusion

The 68 Gateway Server with Remote Schema Stitching architecture paves the way for the APIs of the future by integrating many systems elegantly, easily, and at scale. With this technique, maintenance, scaling, and iteration become far simpler. The examples above demonstrate just how powerful GraphQL and the JavaScript ecosystem are at unifying data without sacrificing flexibility or security.

If your company is moving toward a microservices architecture, give this pattern a chance—who knows, you might be the next team to successfully carry legacy services into the future!


Don’t forget to share and discuss your experience building an API Gateway in the comments! 🚀

Related Articles

💬 Comments