API / Apollo Gateway Interview questions
1. What is Apollo Gateway?
Apollo Gateway is the @apollo/gateway npm package that extends Apollo Server so it can act as a single entry point for a federated GraphQL architecture. Instead of resolving data itself, it takes an incoming query, breaks it into a query plan, and dispatches the underlying pieces to the individua...
2. What is GraphQL Federation?
Federation is an architectural pattern for splitting one GraphQL API across multiple independently deployable services, called subgraphs, while still exposing a single unified schema to clients. Each team owns a subgraph containing the types and fields relevant to its domain — for example a...
3. What is a subgraph in Apollo Federation?
A subgraph is an individual GraphQL service that owns a specific slice of the overall graph — for instance a Products service or a Reviews service. Each one exposes its own schema, annotated with federation directives such as @key , and can be built, tested, and deployed independently of ev...
4. What is a supergraph in Apollo Federation?
The supergraph is the single composed schema that results from merging every subgraph's schema through Federation's composition algorithm. It's the schema clients actually query against — they have no visibility into how many subgraphs sit behind it or how the data is split. Beyond the merg...
5. What is the difference between Apollo Server and Apollo Gateway?
Apollo Server is a standalone GraphQL server: you give it a schema and resolvers and it executes queries against them directly. Apollo Gateway is not a full server on its own — it's a package that plugs into an Apollo Server instance so that instance behaves as an orchestrator instead of a ...
6. What is Apollo Federation 2?
Federation 2 is the second major version of Apollo's federation specification. It keeps the same core idea — composing many subgraph schemas into one supergraph — but relaxes several of Federation 1's stricter composition rules and adds new directives that make common patterns easier ...
7. What are entities in Apollo Federation?
An entity is an object type whose data is split across more than one subgraph and identified by a unique key. A classic example is a Product type: the Products subgraph owns most of its fields, but the Reviews subgraph also contributes a computed field like averageRating without owning the rest o...
8. What is the @key directive used for?
@key marks the field or fields that uniquely identify instances of an entity type, which is what lets other subgraphs reference and extend that type without owning it fully. type Product @key(fields: "id") { id: ID! name: String! price: Float! } Any subgraph that wants to contribute additional fi...
9. What is schema composition in Apollo Federation?
Schema composition is the process of combining every subgraph's SDL into a single supergraph schema. The composer validates that types agree across subgraphs — for instance, that a field defined in two places has a matching type, or that a field intentionally shared across subgraphs is actu...
10. What is managed federation?
Managed federation is Apollo's approach where subgraph schemas are registered with GraphOS rather than the gateway or router polling each subgraph directly and composing locally on its own. When a team publishes a new subgraph schema with Rover, GraphOS validates it, runs composition centrally, a...
11. What is Apollo Studio / GraphOS?
GraphOS (formerly branded as Apollo Studio) is Apollo's cloud control plane for a federated graph. It's where the schema registry lives, where composition runs centrally, and where you get observability into your graph in production. Schema registry and change history for every subgraph Centraliz...
12. What is Rover CLI used for?
Rover is Apollo's command-line tool for interacting with a federated graph and with GraphOS. It's the tool teams run in CI and locally to publish, validate, and inspect schemas. rover subgraph publish – registers a new subgraph schema version with GraphOS. rover subgraph check – valid...
13. What is a query plan?
A query plan is the ordered set of fetch steps the gateway or router generates for a single incoming operation. It describes which subgraph(s) need to be called, whether those calls can happen in parallel or must happen in sequence, and how the entity representations needed for join steps get pas...
14. What are the main directives used in Apollo Federation?
Federation relies on a small set of schema directives to describe how types and fields relate across subgraphs. The main ones are: @key – marks the field(s) that uniquely identify an entity. @external – declares that a field is defined in another subgraph, used alongside @requires/@pr...
15. What is the difference between Apollo Gateway and Apollo Router?
Both act as the entry point for a federated graph, but they're built very differently and Apollo now recommends Router for new work. Apollo Gateway Apollo Router Node.js package (@apollo/gateway) built on Apollo Server Precompiled Rust binary Lower throughput, higher latency under load Significan...
16. Why do we use Apollo Federation instead of GraphQL schema stitching?
Schema stitching requires a central gateway service to know the full shape of every downstream schema and manually merge them with delegation and merge functions. As more teams and schemas get added, that central merge logic becomes a bottleneck — every schema change anywhere in the graph r...
17. How does Apollo Gateway compose a supergraph?
Composition can happen in two ways depending on setup, but the overall flow is the same: Gateway (or GraphOS, in managed mode) fetches each subgraph's SDL, either via the _service {{ sdl }} introspection field (unmanaged/IntrospectAndCompose) or from GraphOS's registry (managed federation). The c...
18. How does the @external directive work?
@external declares that a field is actually owned and defined by another subgraph, and this subgraph is only referencing it — typically because it needs that field's value as an input to @requires , or is supplying it via @provides . type Product @key(fields: "id") { id: ID! weight: Float! ...
19. How does the @requires directive work?
@requires lets a subgraph declare that computing one of its own fields depends on a field it doesn't own, coming from that entity's owning subgraph. type Product @key(fields: "id") { id: ID! weight: Float! @external estimatedShippingCost: Float! @requires(fields: "weight") } Here the Shipping sub...
20. How does the @provides directive work?
@provides is the mirror image of @requires . It lets a subgraph declare that, when it resolves a field returning an entity, it can also directly supply certain fields of that entity itself — letting the query planner skip an otherwise-necessary extra round trip to the owning subgraph. type ...
21. What is the difference between @shareable and @override?
Both are Federation 2 directives, but they solve different problems. @shareable @override Declares a field is intentionally resolvable by more than one subgraph at the same time Declares a field's ownership has moved from one subgraph to another Used for fields that genuinely make sense to comput...
22. When should you use Apollo Router instead of Apollo Gateway?
For most new federated projects today, Router is the better starting point. A few concrete signals make the case even stronger: High request volume – Router's Rust runtime handles far more requests per second with lower and more consistent latency than the Node.js Gateway. Subscriptions &nd...
23. How do you configure Apollo Gateway with Apollo Server?
You construct an ApolloGateway instance and pass it to ApolloServer in place of a local schema. In development, it's common to use IntrospectAndCompose to compose locally from a static list of subgraph URLs; in production, managed federation is preferred instead. const { ApolloServer } = require ...
24. What happens when a subgraph is unavailable at runtime?
If a query needs data from a subgraph that's down or unreachable, the gateway doesn't necessarily fail the whole request. It still resolves whatever it can from the healthy subgraphs, and returns a GraphQL error — scoped to the affected field's path — for the parts that depended on th...
25. How does Apollo Gateway handle authentication and authorization?
Gateway doesn't implement auth logic out of the box — that responsibility is typically split between the gateway layer and each subgraph. A common pattern: the gateway validates or parses the incoming token (a JWT, say) via a custom data source, and forwards the relevant claims to subgraphs...
26. Why doesn't Apollo Gateway support GraphQL subscriptions as robustly as Apollo Router does?
Apollo Gateway's Node.js implementation was designed around federated execution of queries and mutations; federated subscriptions — where a long-lived connection needs to be composed and kept open across multiple subgraphs — were never a first-class design goal for it, so support is l...
27. What is the difference between Federation 1 and Federation 2?
Federation 2 is a compatible evolution of Federation 1, but it changes several composition rules and adds directives that make common cross-subgraph patterns safer to express. Federation 1 Federation 2 Entities defined with a "base" type in one subgraph, extended via @extends elsewhere Any subgra...
28. How do you debug query planning issues in Apollo Gateway?
Unexpected latency or extra network hops in a federated query is almost always a query-planning issue, and there's a fairly standard way to track it down. Inspect the actual query plan — Apollo Sandbox has a query plan panel that visualizes fetch nodes, showing which are sequential versus p...
29. What is the difference between IntrospectAndCompose and managed federation in Apollo Gateway?
Both get you a composed supergraph, but they differ in where composition happens and how much governance you get. IntrospectAndCompose has the gateway itself poll each subgraph's URL directly, introspect its schema via the _service field, and compose locally in-process — typically on startu...
30. How can you optimize Apollo Gateway performance?
Performance work on a federated gateway spans both infrastructure choices and schema design. Migrate to Apollo Router for the biggest single win — its Rust runtime handles substantially more throughput at lower latency than the Node.js Gateway. Use @provides where a subgraph can cheaply sup...
31. Explain the lifecycle of a GraphQL request through Apollo Gateway?
A request passing through a federated gateway goes through a fairly fixed sequence of stages before a response comes back to the client. flowchart TD A["Client sends GraphQL query"] --> B["Gateway parses and validates against the supergraph schema"] B --> C{"Query plan already cached?"} C -->|Yes...
32. Explain the internal working of entity resolution using _entities and reference resolvers?
When Subgraph B needs to contribute fields to an entity it doesn't own, the gateway calls a special field that Federation automatically adds to every subgraph's schema: _entities(representations: [_Any!]!): [_Entity]! . The flow looks like this: the gateway first fetches the entity's base data (i...
33. What is the difference between a monolithic GraphQL server and a federated Apollo Gateway architecture?
Both expose one GraphQL endpoint to clients, but how that endpoint is implemented and who owns it differ substantially. Monolithic GraphQL server Federated gateway architecture One deployable containing the whole schema and all resolvers Schema split by domain across independently deployable subg...
34. How does Apollo Gateway handle errors returned by subgraphs?
Subgraph-level GraphQL errors get propagated into the top-level errors array of the gateway's response, but with the path rewritten to reflect where that field sits in the client's original query — not the internal subgraph request the gateway happened to send. Field values follow normal Gr...
35. What is the purpose of the _service and _entities fields in a federated subgraph schema?
Both are automatically added to every subgraph's schema by a federation library like @apollo/subgraph — you don't hand-write either one. _service { sdl } – lets the gateway fetch a subgraph's raw, federation-annotated schema string during composition, without the subgraph needing a se...
36. How do you implement custom middleware or plugins in Apollo Gateway?
Apollo Gateway doesn't have a plugin system of its own separate from Apollo Server — the main extension point for touching outgoing subgraph requests and incoming subgraph responses is overriding buildService to supply a custom RemoteGraphQLDataSource . const { ApolloGateway, RemoteGraphQLD...
37. What are contract variants in GraphOS?
Contracts let you publish a filtered view of the full supergraph to a specific audience, without hand-maintaining a second schema by hand. You tag fields and types in your subgraph schemas with @tag , then define a contract that includes or excludes fields based on those tags (or you can hide som...
38. How do you handle the N+1 query problem when a field spans multiple subgraphs?
N+1 concerns actually show up at two different levels in a federated graph, and each needs its own fix. Inside a single subgraph , it's the same problem as any GraphQL server: a naive resolver that queries a database once per item in a list. The fix is the usual one — batch and cache lookup...
39. What is the difference between @override and @external for migrating fields?
Both can technically be used while relocating a field, but they were designed for different purposes and @override is the purpose-built tool for the job. The @external + @requires / @provides combination was originally meant to express genuine cross-subgraph data dependencies — "I need this...
40. How does Apollo Gateway / Router handle caching?
Caching in a federated graph happens at a few different layers, and support differs somewhat between Gateway and Router. Query plan caching – both Gateway and Router cache the generated plan for a given operation shape, avoiding re-planning identical queries. Automatic Persisted Queries (AP...
41. Explain the execution flow of a federated query spanning three subgraphs?
Take a query asking for a product's name, its reviews, and each reviewer's display name — with Products, Reviews, and Users each owning a different piece. sequenceDiagram participant C as Client participant G as Gateway participant P as Products subgraph participant R as Reviews subgraph pa...
42. Which is better and why: Apollo Router or Apollo Gateway, for a high-throughput production system?
For a high-throughput production system, Apollo Router is the stronger choice, and the reasoning holds up on more than just raw benchmarks. Its Rust runtime delivers meaningfully higher throughput and lower, more consistent latency under load than the Node.js-based Gateway, largely because Rust's...
43. How do you secure inter-service communication between the gateway and subgraphs?
Subgraphs generally shouldn't be reachable from anywhere except the gateway, and the gateway's own calls should be authenticated as coming from a trusted source. Network isolation – place subgraphs on a private network or VPC so they aren't publicly addressable at all; only the gateway/rout...
44. What are Automatic Persisted Queries (APQ) and how do they work with Apollo Gateway?
Automatic Persisted Queries let a client send a short SHA-256 hash of a query instead of the full query text on every request, which matters especially for large federated operations sent over slow or mobile networks. The client computes a SHA-256 hash of the query and sends just the hash on the ...
45. How do you handle versioning and backward compatibility of subgraph schemas?
A federated graph changes constantly across many independently-owned subgraphs, so backward compatibility is managed through process as much as through schema design. Schema checks in CI – run rover subgraph check against real production traffic samples before merging, so a potentially brea...
46. What is the difference between self-hosted Apollo Router and the GraphOS Router (cloud)?
Both run the same Router technology, but who operates it — and how much infrastructure control you keep — differs. Self-hosted Apollo Router GraphOS Router (cloud) You run the router binary/container yourself, on your own infra Apollo runs and scales the router for you as a managed se...
47. How do you troubleshoot composition errors when publishing a new subgraph schema?
Composition errors are usually specific and actionable if you read them closely rather than guessing. Read the exact error message — Rover/GraphOS typically names the specific field or type and the reason, such as a field having a mismatched type across two subgraphs. If the conflict is a f...
48. Explain the internal working of query plan caching?
Query planning — deciding which subgraphs to call, in what order, and how to stitch the results — is a moderately expensive step, but it only depends on the shape of an operation, not on the actual variable values passed at runtime. That's the property query plan caching exploits. Whe...
49. How can you implement rate limiting at the Apollo Gateway or Router level?
The right approach differs a bit depending on whether you're running Router or the older Node.js Gateway. Apollo Router supports request-level rate limiting directly in its configuration for GraphOS Enterprise plans, and can also be extended with a Rhai script or an external coprocessor that insp...
50. What is the future direction of Apollo Gateway compared to Apollo Router?
Apollo has been consistent in its guidance: Apollo Router is the actively developed, recommended runtime for federation going forward, and Apollo Gateway is in maintenance mode. Gateway still receives compatibility and security fixes, and existing production deployments continue to work, but new ...