← Lessons

quiz vs the machine

Platinum1800

System Design

The GraphQL Gateway

Unify many services behind one typed graph that clients query precisely.

6 min read · advanced · beat Platinum to climb

What a GraphQL gateway does

A GraphQL gateway exposes one typed schema that stitches together many backend services. Clients ask for exactly the fields they need in a single query.

  • It resolves each field by calling the owning service.
  • It composes subschemas into one supergraph, often via federation.
  • Clients avoid overfetching and underfetching by shaping the response themselves.

How a query resolves

One client query fans out to several services, then the gateway assembles the result.

Benefits

  • A single round trip can gather data that REST would need many calls for.
  • The typed schema documents the API and catches errors early.
  • Each team owns its subgraph independently.

Hard parts

  • The N plus one problem appears when a field resolves per item; batch with a loader.
  • Caching is harder than REST because queries vary in shape.
  • A complex query can be expensive, so enforce depth and cost limits.

Key idea

A GraphQL gateway federates services into one typed graph so clients fetch exactly what they need, but you must guard against N plus one and costly queries.

Check yourself

Answer to earn rating on the learn ladder.

1. What problem does a GraphQL gateway solve for clients?

2. How do you mitigate the N plus one problem in a resolver?

3. Why enforce depth and cost limits?