Why headless GraphQL caching decides storefront speed
A team building a headless front end on Magento Open Source often finds that every product listing, category page and cart lookup sends a GraphQL request to PHP, and that the store slows as traffic grows. Cache hits depend on three things: the HTTP method the front end uses, whether the query is cacheable at all, and whether a cache layer sits in front of Magento to serve repeated responses. If any one of these is missing, most requests reach the application server.
Magento's GraphQL endpoint can return cacheable responses for eligible queries, and the front end must send them in a way that lets those responses be stored and reused. Adobe's developer documentation describes how cacheable GraphQL responses are identified and how the X-Magento-Cache-Id header is used to keep cached entries separate. Mutations and queries that depend on customer or session data are not cached in the same way, so a headless team should map its query list against the rules in the release it runs. For self-managed installations, Adobe documents Varnish as the full-page cache accelerator, so the cache layer that serves these responses is typically Varnish rather than a separate CDN product.
Before committing to a design, confirm the exact caching behavior against the Adobe pages for the Magento Open Source release in use, since query handling has changed between 2.4.x lines. Check which queries your front end sends, whether they are issued as GET or POST, and whether Varnish is configured to cache the GraphQL responses you expect. A simple test is to repeat the same query and compare response headers and server load on the second request. Teams that skip this check often discover the cache layer is not doing the work they assumed only after launch.
Request method and cache layer options compared
This table compares how GraphQL queries are delivered and where they can be cached for a headless Magento storefront. Read each row against your front end's query mix: the cache hit rate you can expect depends on whether queries use GET, whether they are cacheable, and whether Varnish sits in front of the endpoint.
| Option | When it fits | Cost to hit rate or effort | What to verify in your release |
|---|---|---|---|
| GET with cacheable queries at Varnish | Read-only catalog, category and CMS queries that return the same data for many shoppers | Lowest hit-rate cost when queries stay identical and stateless; requires a VCL that keys on the cache header | Confirm the Varnish VCL handles the GraphQL endpoint in your 2.4.x line and that the cache ID header is passed through |
| POST queries at Varnish | Clients that send long query strings or variables that GET cannot carry cleanly | Usually not cached by default, so most reads go to the application and hit rate falls | Test whether your front-end client can switch those reads to GET before relying on Varnish |
| Application-level caching only | Small stores, or teams without Varnish operations skills | Every request still reaches PHP and the cache backend, so load and latency are higher | Check the Magento cache types and backend settings for your deployment, and measure response times under load |
| Customer-specific queries | Cart, account and personalized price queries | Usually bypass shared caches, so they add load regardless of layer | Confirm which responses carry customer or cart context and that they are not stored in a shared cache |
| Query design: stable variables and fields | Product listing and detail queries reused across pages | Requesting extra fields or unique variable values fragments cache keys and lowers hits | Review query text in your front-end code and compare hit rate before and after changes |
| Cache-key handling with X-Magento-Cache-Id | Shared caching of GraphQL responses keyed by store and query | Misconfigured or missing keys cause cache misses or incorrect shared responses | Verify header behavior against the Adobe GraphQL caching documentation for your exact release |
| Varnish purge on catalog changes | Storefronts where prices or stock change during the day | Frequent purges lower hit rate; infrequent purges risk stale data | Confirm which admin events trigger invalidation and test a price change end to end |
| Security review of cached responses | Any shared cache holding GraphQL data | Adds review and test effort, especially for customer data | Confirm no customer or cart data is stored in a shared cache and record the evidence for your assessor |
Which GraphQL queries are worth caching
Not every query in a headless Magento storefront can be cached the same way. The cards below sort common query types by whether a shared cache can serve them safely, and why. Cacheability depends on what each query returns and who it returns it for, so treat each verdict as a starting point to confirm against your own schema and customizations.
Product and category reads
Catalog queries such as product details and category listings return the same data to every anonymous shopper, which makes them the strongest candidates for a shared cache. Caching fits well here because the response depends on the store and the requested fields, not the visitor. Check that your storefront does not add per-customer fields, such as customer group pricing, to these same queries. Confirm that catalog changes trigger the invalidation you expect, so shoppers do not see stale prices or stock states.
CMS page and block content
CMS pages and blocks change rarely and are requested by many visitors, so they are a low-risk cache target. Their main risk is staleness after an editor publishes a change, which makes invalidation timing the key check. Confirm that content updates purge the relevant cache entries in your environment rather than waiting for a timed expiry. Keep any personalized blocks out of this group, since they are rendered per visitor.
Customer-specific data
Queries that return a customer's name, addresses, orders, wishlist or account settings must never be served from a shared cache. Returning one customer's data to another is a privacy incident, and it is also a PCI DSS and GDPR concern. These queries require a request that carries the customer's authorization, and the cache must not store their responses for anyone else. Ask your team to confirm, for each query, which header or token decides whether the response may be cached.
Cart and checkout mutations
Mutations that add items, set addresses or place orders change state and are sent as POST requests, so they are not cached. Cart queries that read a quote tied to a session are also user-specific and must bypass the shared cache. Test that a cart read after an add-to-cart call returns the new contents, not a cached earlier response. Confirm that the cart identifier is never reused across shoppers.
Personalized pricing and promotions
Prices that depend on customer group, company account, or applied coupons vary by visitor, even when the product query looks identical. A shared cache can serve the wrong price if the cache key ignores the factors that change the result. Decide whether these fields come from a separate, per-user query or from a context-aware cache key, and document the choice. Review pricing rules with your merchandising and finance teams before enabling any cache for these queries.
How to set up cached GraphQL reads with Varnish
This sequence takes a headless Magento Open Source storefront from a supported stack to a verified state where cacheable GraphQL reads are served from Varnish and mutations and personalized queries always reach the origin. Each step ends with a check your team can repeat.
Confirm the supported stack for your release
Your platform or solutions architect checks the release you plan to run against Adobe's system requirements before any configuration changes. For 2.4.9, the listed stack includes nginx 1.30 and Redis or Valkey 9, and the requirements page lists the Varnish version that applies to your release line. For 2.4.8-p5, Varnish 8 is listed alongside nginx 1.30. Confirm that every component in your environment matches a listed combination, because Adobe supports only those combinations. You are done when the team has a written version matrix signed off by whoever owns the platform.
Route GraphQL requests through the cache layer
Your infrastructure team points the storefront's GraphQL endpoint at Varnish rather than directly at the PHP origin, and passes the required headers through the web server and load balancer. Varnish is the full-page cache accelerator Adobe documents for self-managed installations, so the GraphQL path has to be handled by the same layer that your VCL defines. Check that a request to the GraphQL endpoint returns a response through Varnish, and that the response includes a Varnish or Age header from the cache layer. If the header is missing, the request is bypassing the cache and the routing needs review before you continue.
Send cacheable queries as GET requests
Your front-end developers change read-only queries from POST to GET, with the query, variables and operation name encoded in the URL. GET requests are the form that shared caches can key on, while POST bodies are generally not cached. Keep the query string stable across requests, because a changed parameter order or an extra variable creates a new cache entry. Confirm the change in a browser's network panel or with a command-line request: the same product or category query should return the same response from the GET endpoint on repeat calls, and the request should show as a GET in your logs.
Verify the X-Magento-Cache-Id header on repeat requests
Your developers and QA engineer send the same cacheable GET query at least twice and read the response headers each time. Magento sets the X-Magento-Cache-Id header on cacheable GraphQL responses, and the value should be identical across repeated identical requests. Record the Varnish hit or miss status alongside it: the first request is usually a miss and later requests should be hits while the object remains valid. If the header changes between identical requests, look for differences in the query string, variables or request headers such as Store or Currency, since these change the cache key. You are done when repeated identical reads show a stable cache ID and a hit status.
Confirm invalidation after a catalog change
Your operations lead updates a test product or category in the admin, then repeats the cached query. The goal is to confirm that the cached response is refreshed once the underlying data changes, rather than served stale. Check that the purge or invalidation path configured for your Varnish setup is triggered by the change, and that the next query returns the updated value. If the old value persists, review the invalidation settings in your VCL and the cache tags that Magento sends. You are done when the test change appears in the GraphQL response after invalidation, and the team has recorded the test in its runbook.
Check that mutations bypass the cache
Your QA engineer sends a cart or customer mutation through the same Varnish endpoint and confirms the response is never served from cache. Mutations change state, so a cached response would show a customer an outdated cart or account. Send the mutation twice with different inputs and check that each response reflects the new input and that Varnish records a pass or miss rather than a hit. Also confirm the mutation's request method is POST. You are done when every mutation tested returns fresh results and none show a cache hit.
Check that personalized queries bypass the cache
Your QA engineer runs queries that return customer-specific data, such as the current cart, wishlist or customer profile, through Varnish using a logged-in session. Shared cache entries for these responses would expose one shopper's data to another, so they must not be stored for anonymous reuse. Compare the responses for two different test customers and confirm they differ and that neither is served as a hit to the other. Confirm the session or authorization header is handled the way your VCL intends. You are done when personalized responses are unique per customer and do not return hits across sessions.
Record the baseline and the rules in your runbook
Your platform team writes down the stack versions, the Varnish configuration in use, the cacheable query list, the headers used to verify hits, and the mutation and personalized query tests with their results. This record becomes the reference for upgrades, since each new release line or Varnish change can alter caching behavior. Ask your implementation partner or internal team to confirm which GraphQL queries are in the cacheable list before the storefront goes live. You are done when the runbook names an owner for the cache rules and a repeatable test for each check.
How a headless GraphQL request reaches the cache or PHP
The request starts at the headless front end, which sends either a GET or a POST to the GraphQL endpoint. It passes through the CDN or edge, then Varnish, which decides whether a cached response can answer it. On a miss, nginx and PHP-FPM run Magento GraphQL and the response is stored only if the query is cacheable. Check the method, the cache key headers, and whether mutations skip the cache entirely.
Decision points for GET versus POST, Varnish hit or miss, and mutations bypassing the cache.
Security risks when caching GraphQL responses
Caching GraphQL responses speeds up a headless storefront, but the same cache that serves anonymous catalog data can also serve one customer's account data to another. The cards below cover the main leak paths, the header and CSP controls Adobe documents for storefront pages, and the tests to run before launch.
Personalized responses leaking across customers
Cart, customer, wishlist and price responses differ by shopper, so caching them under a shared key can return one customer's data to another. Before enabling caching, list every query your front end sends and mark which ones return personal or account-specific fields. Test with two customer accounts and confirm that a cached response for one account is never returned to the other or to a guest.
Magento 2 sourceTokens kept out of cache keys
Customer tokens sent in the Authorization header must never become part of a cache key or be written into a cached response body. Check whether your front end or CDN forwards the header into the cache key, and whether any response echoes a token or session identifier. Confirm the behavior in your own environment with captured requests, since header handling depends on your proxy and cache configuration.
Customer data in cached bodies
Even when the cache key is correct, a response can carry names, addresses or order details that should never be stored in a shared cache. Review the field list of each cacheable query and remove personal fields from it. Look for the same data in the response headers as well as the body, and confirm that personal responses are excluded from any page-level cache.
Purge and invalidation hygiene
A stale or wrongly scoped purge can keep a previous customer's data alive or expose a price change for hours. Define which events purge which cache tags, restrict who can call the purge endpoint, and make sure purge requests come only from your own Magento and cache hosts. Test a catalog change, a price change and a logout, and confirm the old content disappears from the cache.
Varnish cache guideCSP and security headers
Adobe documents Content Security Policy headers in Magento Open Source from version 2.3.5, and from 2.4.7 CSP runs in restrict mode by default on storefront and admin payment pages. Confirm that your headless storefront and any proxy or cache in front of it keep the policy headers intact and do not strip or cache them with another user's response. Test the headers on each page type after every deployment.
CSP documentationTesting before launch
Build a test plan that replays authenticated and anonymous sessions through the cache and checks each response for cross-user data. Include logout, token expiry, session timeout and a cache purge during an active session. Record the results and repeat the tests after each Magento patch, because security patches and CSP defaults change between 2.4.x releases.
Questions teams ask before caching headless GraphQL
Is GET always better than POST for headless GraphQL caching?
No. GET is usually the better choice for read-only queries because the query can be keyed and cached by URL at the proxy, while POST requests are generally not cached by default. The catch is that GET requests carry the query and variables in the URL, so long queries can hit length limits and cached responses must still vary by the right inputs. Mutations should always use POST, and any query that returns personal data needs a cache key that separates shoppers. Confirm how your front end client sends each operation and which queries it sends before you assume caching will work.
Is Varnish required to cache Magento GraphQL responses?
Varnish is not strictly required to use Magento's own cache, but it is the layer that matters most for GraphQL at the edge. Adobe documents Varnish as the full-page cache accelerator for self-managed installations, and a headless storefront depends on it to serve cached GraphQL responses before requests reach PHP. Without an edge cache, every read query still runs through the application, which limits how much the front end benefits from caching. Confirm the Varnish version your release supports in Adobe's system requirements, since those lists change with each release line.
How long does GraphQL caching work take, and what drives the effort?
Effort depends mainly on how many queries the storefront sends, how much of the data is personalized, and how much of the cache design already exists. Teams with a small set of read queries and anonymous catalog pages need less work than teams with customer-specific pricing, carts and account data in the same queries. Other drivers include the number of custom GraphQL resolvers, the state of the Varnish configuration, and how many environments must be tested. No duration figure is given here. Ask any partner for a written breakdown of query inventory, cache rules, testing and handover before accepting a timeline.
What does our team need to provide for a GraphQL caching project?
A caching project needs access to the store and its front end code, plus people who can explain the business rules behind each query. The team should provide:
- A copy of the storefront query set, with each query's operation type and variables
- Staging and production access for Magento, Varnish and the front end build
- Decisions on which data may be cached per customer, store view and currency
- Named contacts for the front end, platform operations and security
Without these inputs, cache rules tend to be guesses, and guesses often cache data that should stay private.
Can our in-house team build GraphQL caching without a partner?
Yes, if the team already runs Magento in production and has engineers who know both GraphQL and Varnish. The work requires understanding how the front end builds queries, how Magento assigns cache identifiers, and how invalidation reaches the proxy after catalog or price changes. Teams without that combination often spend their time on the cache keys and test cases rather than on the feature itself. A partner can cover the gaps, or review an in-house design. Decide based on who will maintain the rules after launch.
What should a quote for GraphQL caching include?
A quote should match the written scope and show each component separately. Ask for:
- A query inventory with a cacheable or not cacheable decision for each query
- The cache key design, including how the X-Magento-Cache-Id header is set and read
- Varnish configuration changes, test plans and cache hit checks in each environment
- Invalidation behavior for catalog, price and customer changes
- Handover documentation and any ongoing support, stated as a separate item
DeployOpen agrees scope, deliverables and timelines in writing before work starts, and prices follow from that scope.
How do Magento upgrades affect GraphQL cache behavior?
Upgrades can change how queries are cached, so cache rules must be retested after every patch or release. Adobe's upgrade guide recommends upgrading every patch cycle to stay secure and PCI compliant, and it names customizations, third-party integrations and coding practices as drivers of upgrade effort. A new release can change the GraphQL schema, the cache identifiers Magento sends, or the Varnish version it supports. Keep the query inventory under version control, and rerun the cache hit checks in staging before each production upgrade.
How DeployOpen scopes and delivers GraphQL caching work
DeployOpen plans, builds and hands over the caching layer behind a headless Magento Open Source storefront, inside infrastructure you control. Work starts from a written scope that covers which GraphQL queries are cached, how the front end sends them, and how Varnish and the cache headers are configured and verified.
How we scope
- Inventory the storefront queries and mutations, marking which are GET-eligible and which must stay uncached
- Confirm the Magento Open Source release line and PHP, MySQL, Varnish and Redis or Valkey versions against Adobe's system requirements
- Agree how the front end sends customer context, such as the X-Magento-Cache-Id header, before any caching rule is written
- Record the written scope, deliverables and timeline before work starts, since engagements are fixed-scope
How we build
- Restructure front-end queries that need caching so they use GET requests with stable, cacheable inputs
- Configure the Varnish caching rules and GraphQL cache handling for your self-managed installation
- Set invalidation so product, category and price changes purge the right cached responses
- Test cache hits and misses for anonymous and logged-in shoppers on a staging copy of your store
How we hand over
- Deliver the exported VCL, front-end query changes and cache header configuration as versioned code
- Document which queries are cached, their invalidation triggers and the reasons for each exclusion
- Provide cache hit rate check steps your team can repeat after each release
- Run a knowledge transfer session so your engineers can change caching rules without a rebuild
How we support
- Review cache behavior after each Magento Open Source patch and minor release that touches GraphQL or caching
- Retest hit rates and invalidation when you add storefront features, extensions or new query shapes
- Offer ongoing support, upgrades and continuous testing as a retainer if you want DeployOpen to keep the layer tuned
- Ask any partner to confirm response time commitments and coverage in the written retainer scope

