Nodea — logo

Varnish Cache

Varnish Cache is a high-performance HTTP accelerator, also called a caching reverse proxy. It is placed in front of the application server, where it intercepts incoming requests and, if it holds a current response, returns it straight from memory — without involving the web server, the database or the application code.

How Varnish works

On the first request, Varnish passes it to the application server (the backend), fetches the response and stores it in RAM. It then handles subsequent identical requests itself, in a fraction of the time needed to generate the page from scratch. The cache's behaviour — what is stored, for how long and for whom — is defined in the VCL configuration language, which allows precise control over caching rules, including short-lived micro-caching for a few seconds.

When to use Varnish

Varnish is especially effective on high-traffic sites where many people view the same, rarely changing content — portals, blogs, stores with popular product pages. By offloading the backend, it dramatically reduces the time to first byte ("TTFB") and lets a site absorb traffic spikes without expanding the server. It is often combined with a CDN: Varnish caches close to the application, while the CDN spreads copies of content closer to users worldwide. The challenge tends to be correctly invalidating the cache after content changes and handling dynamic, personalised pages that do not suit simple caching and require carefully designed rules.

Powiązane pojęcia

Najczęstsze pytania

How does Varnish differ from a CDN?

Varnish usually runs on your server and caches responses close to the application, while a CDN spreads copies of content around the world, closer to users. The two are often combined for maximum acceleration.