API / Apollo Gateway Interview questions
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 (APQ) – caches full query text server-side against a hash, so repeat requests only need to send the hash.
- Response/field caching via @cacheControl – subgraphs can annotate fields with cache hints (max age, scope), which propagate up so a caching layer knows how long a piece of data is safe to reuse.
- Distributed caching – Router additionally supports an external cache (such as Redis) for query plans and APQ entries shared across a fleet of router instances, rather than each instance keeping its own separate in-memory cache.
Many of the more advanced caching features — distributed entity caching in particular — are Router-first in current development, another point in favor of Router for graphs with serious caching requirements.
More Related questions...