API / Apollo Gateway Interview questions
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 lookups within a request using a DataLoader-style pattern.
Across subgraphs, the good news is that Federation's entity resolution is already batched by design: the gateway calls a subgraph's _entities field once per query, passing an array of representations for every instance that subgraph needs to resolve — not once per row. So resolving reviewer names for 50 reviews is one _entities call to the Users subgraph with 50 representations, not 50 separate calls.
What still matters on the schema-design side is avoiding deeply chained @requires relationships, since each additional dependency hop is still a real round trip, even if each hop itself is properly batched.
More Related questions...