What is Magento Varnish Cache ?
Varnish is Magento’s officially recommended full-page cache (FPC) backend — a high-performance HTTP reverse proxy that sits in front of the Magento web server and serves cached HTML in under 50 ms. Magento ships a VCL generator and ESI hole-punching for cart / mini-cart / welcome blocks, so per-user content lives in shared cached pages. Open-source BSD — typically 5 – 10x faster TTFB than the built-in FPC.
Five things Varnish actually does for your Magento store
Varnish isn't a Magento module — it's a separate reverse-proxy daemon that Magento integrates with via VCL, headers, and a generator command. Here's the wiring concretely.
-
01
Install Varnish 6 or 7 on the same box (or upstream)
Varnish sits in front of your Magento web server as a high-performance HTTP reverse proxy. On a standard single-server stack you install it via apt (Debian/Ubuntu) or yum (RHEL/Alma) on the same machine, bind it to port 6081 (or 80 if it’s the public entry point), and configure it to forward misses to nginx on 8080 or Apache on 8081. On multi-server setups Varnish lives on its own box or fronts a load-balancer pool. Magento 2.4.x officially supports Varnish 6.x and 7.x.
-
02
Tell Magento where Varnish is
Run
bin/magento setup:config:set --http-cache-hosts=127.0.0.1:6081so Magento knows which Varnish daemon to send purge requests to. Multiple hosts are comma-separated. This writes toapp/etc/env.phpand survivessetup:upgrade. Without this setting Magento renders pages correctly but never invalidates Varnish — stale catalogue pages pile up forever and you spend Friday afternoon wondering why a price change isn’t live. -
03
Switch the FPC backend to Varnish in admin
In admin go to Stores → Configuration → Advanced → System → Full Page Cache and change Caching Application from "Built-in Cache" to "Varnish Cache". This swap is exclusive — Magento can only have one FPC backend at a time. You cannot mix Built-in FPC and Varnish, and you cannot run Redis as the FPC backend either (Redis handles block / config cache; FPC is a separate slot).
-
04
Generate the VCL with bin/magento varnish:vcl:generate
Magento ships a generator that produces a working VCL (Varnish Configuration Language) file tuned for your store:
bin/magento varnish:vcl:generate > /etc/varnish/default.vcl. The generated VCL handles X-Magento-Tags headers, cache-key normalisation, ESI block fetching, and the admin-purge endpoint. Always regenerate after a Magento minor upgrade — header rules and built-in routes change between 2.4.4, 2.4.6, 2.4.7 and 2.4.8. -
05
ESI hole-punches dynamic content into shared cached pages
A product page is the same HTML for every visitor — except the mini-cart, welcome message, and customer-section data, which are per-user. Varnish caches the page once and uses ESI (Edge Side Includes) to fetch just the dynamic fragments per request. Magento sends
X-Magento-Tagson every response listing which entities the page depends on (catalog_product_1234, cms_block_5); on admin save Magento sends a PURGE with those tags and Varnish invalidates every matching cached entry in one sweep.
Four situations where Varnish is the obvious answer
The built-in FPC is fine for dev and small stores. These four scenarios are where Varnish stops being optional.
-
Production stores with >1k SKUs and >100 req/min
Once a store has more than ~1,000 SKUs and sustains >100 requests per minute, Magento’s Built-in FPC starts thrashing the database — every miss writes a serialised payload back into
cache_page, and Redis-backed Built-in FPC ties up memory that block-cache wants. Varnish keeps the FPC entirely in RAM in front of PHP-FPM, so origin CPU drops 60 – 80% and TTFB stays under 50 ms even under spike load. This is the single biggest perf win available on a Magento stack. -
Adobe Commerce Cloud (Varnish is shipped + managed)
If you’re on Adobe Commerce Cloud (ACC), Varnish is already running — it ships in every environment from Integration to Staging to Production, managed by Adobe. The VCL is auto-deployed, headers are pre-configured, and the Fastly edge layer in front of Varnish adds a second cache tier. You don’t install or maintain it, but you absolutely should understand it: ESI hole-punching rules, cache-tag headers, and purge behaviour are the same as self-hosted Varnish, and that’s where most ACC perf debugging happens.
-
High-traffic seasonal peaks (BFCM, Diwali, sale launches)
Black Friday / Cyber Monday, Diwali, back-to-school, end-of-season clearance — any event where traffic spikes 5x – 20x for 48 hours. Without Varnish your origin servers melt: every category page miss costs 400 – 900 ms of PHP, every checkout step queues behind it, and Lighthouse on mobile tanks under load. With Varnish + ESI the origin only renders cache-miss pages and dynamic fragments, so the same hardware handles 10x the traffic with cached TTFB under 50 ms. Migrate before, never during, the peak.
-
Sites running a CDN that wants an origin offload
A CDN (Cloudflare, Akamai, AWS CloudFront) caches at the edge — but on a miss it still hits your origin, and that origin needs to respond fast or your CDN cache-fill latency dominates. Putting Varnish between the CDN and Magento gives you a two-tier cache: CDN serves edge hits in <10 ms, Varnish serves origin hits in <50 ms, and only true misses (admin saves, fresh purges, uncached URLs) hit PHP. Pair Varnish with a CDN — they solve different problems and stack cleanly.
Three traps that turn a Varnish rollout into a rescue project
Every Varnish-on-Magento bug I've been called in to fix lands in one of these three buckets. Avoid them and the FPC layer runs silently in the background — exactly what you want from cache infrastructure.
-
Caching personalised content (the cross-customer cart leak)
The single worst mistake. If you cache the full HTML of a page that contains a mini-cart, welcome message, or "Recently viewed" block — and you skip ESI hole-punching — Varnish will serve customer A’s mini-cart to customer B. The Magento-shipped VCL does ESI correctly out of the box, but custom themes or careless block edits routinely break it. Always test with two separate browsers logged in as different customers, add different items to each cart, and confirm each session sees only its own cart. If both carts merge in either browser, you have an ESI break and a GDPR incident waiting to happen.
-
Skipping the VCL regeneration after a Magento upgrade
Magento changes its X-Magento-Tags header format, admin-purge route, and cache-key rules between minor versions. A VCL generated on 2.4.4 will run on 2.4.7 — but it will mis-handle some cache-tag patterns, leak some dynamic blocks, and miss some invalidations. Symptoms are subtle: stale prices for some products, stale stock for others, and occasional flashes of someone else’s data. Every Magento upgrade must include
bin/magento varnish:vcl:generate > /etc/varnish/default.vclfollowed byvarnishadm vcl.load+vcl.use. Bake it into the deploy script. -
Forgetting vcl_purge — stale pages after admin saves
If
vcl_purgeis missing or misconfigured, Magento sends PURGE requests to Varnish on admin save but Varnish ignores them. Pages cache forever, prices stay stale, "Save" in admin appears to do nothing on the storefront. Debug withvarnishlog -g request -q "ReqMethod eq PURGE"to see whether the purge is reaching Varnish, and add theX-Magento-Cache-Debug: srcacheheader to see HIT / MISS / PASS per response. The Magento-generated VCL handles this correctly — the bug is always custom overrides that drop the purge ACL or strip the cache-tag header.
Magento Varnish Cache — frequently asked questions
-
Varnish vs Magento built-in FPC — what is the real performance gap?
Typically 5 – 10x on TTFB under load. Built-in FPC stores serialised page payloads in Redis (or filesystem); every hit costs a Redis round-trip, an unserialise, and a PHP-FPM worker. Cold-cache TTFB is 250 – 600 ms, warm-cache TTFB is 80 – 180 ms. Varnish keeps the rendered HTML entirely in RAM in front of PHP — cached TTFB drops to 10 – 50 ms regardless of cache state, and uncached pages don’t bottleneck because Varnish serialises the slow path away from the fast path. On a store doing 200 req/min the difference between Built-in FPC and Varnish is the difference between "site is fine" and "site falls over during a sale". -
Do I need Varnish if I am already on Cloudflare or a CDN?
Yes — they solve different problems and stack cleanly. A CDN caches at the edge (Cloudflare, Fastly, CloudFront, Akamai), but on a miss the CDN still hits your origin. If your origin is slow on a miss, every cache-fill takes 800 ms and the first visitor in every region pays for it. Varnish in front of Magento makes the origin fast on misses (sub-50 ms instead of sub-second), so CDN cache-fills are quick and the overall edge-cache hit rate climbs because pages don’t expire before they get warm. The standard performant Magento stack in 2026 is CDN → Varnish → nginx → PHP-FPM → Redis (block / session) + OpenSearch (catalogue) + MySQL. -
How do I purge Varnish for one URL?
Send a PURGE request directly: <code>curl -X PURGE -H "Host: example.com" http://127.0.0.1:6081/p/some-product.html</code>. Magento’s admin-save flow does this automatically by sending PURGE with <code>X-Magento-Tags</code> headers so Varnish can purge by tag (every page touching catalog_product_1234) rather than by URL. For manual cache flush, <code>bin/magento cache:flush full_page</code> on the Magento CLI iterates the http-cache-hosts list and issues a PURGE.* (regex-all) request to wipe everything. Always verify the purge worked by re-requesting the URL with <code>-H "X-Magento-Cache-Debug: srcache"</code> and checking for MISS → HIT transitions. -
Why does my cart show another customer’s items?
ESI hole-punching is broken — the mini-cart block is being cached as part of the full page instead of being fetched per-request. Three causes in order of frequency: (1) custom theme overrode the <code>minicart</code> block and dropped the <code>ttl="0"</code> / <code>cacheable="false"</code> attribute, (2) the generated VCL is missing <code>vcl_recv</code> ESI logic because it wasn’t regenerated after a Magento upgrade, (3) a CDN (Cloudflare in Full caching mode, Fastly without origin-shielding rules) is caching the full HTML in front of Varnish. Fix: regenerate the VCL, audit <code>cacheable="false"</code> on every block in customer_section_load, and add <code>Cache-Control: private</code> to the customer-section response. Test by logging in as two different customers in two different browsers and adding different items to each cart. -
Does Hyvä change anything about Varnish?
No — Hyvä is purely a frontend rewrite (Tailwind + Alpine.js replacing KnockoutJS), so the server-side rendering layer that Varnish caches is unchanged. X-Magento-Tags, ESI blocks, purge flow, VCL — all identical between Luma and Hyvä stores. Hyvä actually makes Varnish more valuable: because Hyvä ships ~85% less JavaScript, cached HTML pages render in under a second even on mid-tier Android, so the perf win from sub-50 ms TTFB is fully realised end-to-end. Build a 2026 Magento stack as Hyvä on the frontend + Varnish on the backend — they’re complementary, not alternatives. -
Can I run Varnish and Redis FPC together?
No — pick one. Magento’s full-page cache slot is exclusive: either "Varnish Cache" or "Built-in Cache" in admin, never both. If you select Built-in Cache, you can back it with Redis for storage (faster than filesystem); if you select Varnish, the Built-in FPC layer is bypassed entirely. What you can — and should — run alongside Varnish is Redis for the <strong>other</strong> cache types: block cache, config cache, session storage, and so on. The standard performant stack is Varnish for FPC, Redis instance 1 for sessions, Redis instance 2 for default + block + config cache, OpenSearch for catalogue, MySQL for the database.
Want a Varnish + Redis audit on your Magento store?
Send your storefront URL — I will run a TTFB + cache-hit-ratio audit, review your VCL, and reply with a written tuning plan, fixed-price quote, and earliest start date. 24-business-hour turnaround.