What is Varnish? Your key questions answered

If you want a high volume of visitors on your website, you'll need both an ultra-fast site and server. There are various tools to make your website as fast as possible, such as caching. And when it comes to caching, Varnish is the top technology. We’re here to answer your essential questions about this powerful yet complex tool.

What is caching?

Caching is a technique used to reduce the load on your resources while maintaining the stability and speed of your application. By storing data in a precomputed format for future use, caching eliminates the need to recompute the same request over and over.

Also read

What's caching and how does it work?

Why is caching essential for a fast website?

No matter how well-coded your website is, spikes in traffic can lead to slowdowns. Without caching, your web server must repeat the same calculations for each visitor. With caching, those calculations happen only once, which prevents your server from becoming overloaded.

Google considers website speed when ranking sites in search results. Simply put, the faster your website, the higher it appears in search results, which brings in more visitors!

Nobody enjoys shopping on a slow-loading website—it’s frustrating, and frustrated customers buy less. Providing a smooth shopping experience, especially for large websites with dynamic elements like e-commerce platforms, is crucial. Caching enhances load times by reducing the number of requests to the server.

Curious about how to speed up your website? Our experts are here to help!

Varnish makes your website the fastest!
Varnish makes your website the fastest!

What is Varnish?

Varnish is a unique form of caching software initially developed as a custom solution to speed up the Norwegian online newspaper www.vg.no and is now used by millions of websites worldwide. Acting as a reverse proxy, Varnish Cache can significantly reduce webpage load times, especially for dynamic, high-traffic websites.

By storing entire web pages in its cache, Varnish intercepts HTTP traffic meant for the web application and delivers cached pages directly to visitors. This approach minimizes the load on the application itself, helping maintain stability and speed.

While other caching technologies like Redis, OPcache, and APCu exist, Varnish is the most widely used and often the recommended choice, especially for web applications that leverage Edge Side Includes (ESI).

The results are impressive: websites using Varnish Cache load 300 to 1000 times faster than those without caching technology.

How does Varnish work?

So, what exactly does Varnish do? Unlike other caching technologies, Varnish caches entire web pages. By storing these pages separately in its cache, Varnish ensures they don’t need to be fetched from the server each time they are reopened, allowing web pages to display much faster. Acting as a reverse proxy, Varnish handles and caches requests for the web server to optimize the performance of dynamic web projects.

When a user requests a web page that hasn’t been cached, Varnish connects to the web application and forwards the original request. The HTTP output of the requested page, once delivered by the application, is then stored in Varnish.

Edge Side Includes (ESI) allows specific parts of a page to be cached while other sections remain dynamic. This is especially useful for delivering both static and personalized content, benefiting both anonymous and logged-in users.

Cached data remains in Varnish until the Time To Live (TTL) expires, which is defined by the "Cache-Control" header in the HTTP response from the application. This header tells Varnish how long to store a web page in the cache.

This is how Varnish software works.
This is how Varnish software works.

Varnish only serves cached pages when it is certain the content is not private. For responses involving authentication or cookies, Varnish delivers the page only to the requesting user rather than caching it for others. The application itself can also instruct Varnish to exclude specific pages from caching. In addition, Varnish has internal rules to determine when to bypass the cache, ensuring up-to-date information when needed.

Varnish can also function as a load balancer. When traffic grows too large for a single server, additional servers can be added to handle the load. Varnish distributes incoming requests among the servers and, if one server becomes unavailable due to maintenance or failure, Varnish removes it from its list and redirects users to the remaining servers.

Varnish supports gradual upgrades, allowing you to implement code changes on each server incrementally without users noticing.

lightning-fast-sites-with-varnish-ebook

Download our free e-book: lightning-fast sites with Varnish

In today’s digital world, fast websites are essential. Varnish caching helps you achieve this by storing and delivering dynamic content from RAM at lightning speed. Discover in our e-book how Varnish can drastically improve your site’s load times for an optimal user experience.

Download it here

What are the benefits of Varnish?

The benefits of Varnish are clear: Varnish offers the speed, stability, and performance essential for any web application. It’s especially useful for dynamic web projects, as it helps manage complexity and traffic volumes—both critical for maintaining high performance.

Varnish can handle a large number of simultaneous connections while using minimal memory. Its CPU usage is also very low. Since Varnish is focused solely on caching, without many additional features, its architecture is highly efficient.

Varnish stores entire pages to reduce the load on the server. Acting as a reverse proxy, it helps alleviate server strain and boosts website speed by caching and efficiently processing requests. By keeping cached items in RAM, Varnish delivers lightning-fast performance.

A Varnish server delivers the following performance metrics:

  • 800,000 requests per second
  • Throughput up to 200 Gbps
  • Latency under one millisecond
Interested in Varnish Cache? Rely on our Varnish experts for a custom solution.
Interested in Varnish Cache? Rely on our Varnish experts for a custom solution.

Do you need Varnish?

At Combell, we recommend Varnish for website owners with substantial static (non-changing) content. While caching is beneficial for any site, if you expect high traffic or are a growing mid-sized company, Varnish is a powerful tool you can rely on. It boosts efficiency by caching pages, leading to faster load times and reduced server load, which can benefit both performance and SEO—even for sites with lower traffic levels.

Tip

Caching with Varnish or Redis is included with every Combell web hosting package and is available with our other hosting solutions as well.

What is VCL (Varnish Configuration Language)?

VCL is a specialized programming language used to define the caching behavior of Varnish.

With VCL, you can perform tasks such as:

Inspecting HTTP requests and responses
Modifying HTTP requests and responses
Controlling cache behavior
Selecting the preferred web server
Setting the Time To Live (TTL) for objects
Enabling communication with external systems
Customizing synthetic HTTP responses

VCL can also be used to write hooks for integrating external code into the application, enhancing the cache’s functionality.

The VCL code resides in a VCL file located on the Varnish server.

How do I install Varnish on my server?

To activate Varnish, the basic setup involves pointing the “www” DNS record of your domain to the Varnish server. If your application adheres to HTTP caching conventions, the rest will follow automatically. When a user requests a webpage, an interaction occurs between the browser and the server, and Varnish Cache speeds up page loading by storing previously loaded content. Getting started with Varnish can be that simple.

In practice, however, it’s important to carefully examine how your web application handles HTTP:

Are there specific parts of web pages that should not be cached?
Are there parts of web pages that can be cached even if they use cookies?
Are there certain cookies that should be removed to ensure proper caching?
Are specific cache variations possible based on cookies?
Does the web application use Cache-Control headers to determine the TTL (time-to-live)?

In certain cases, some objects may need to be explicitly removed from the cache.

For example, consider the homepage of a news site. If there’s breaking news, the site won’t want to wait for the TTL of cached content to expire. Instead, the relevant pages need to be removed from the cache immediately.

Popular platforms like WordPress, Drupal, Joomla, and Magento offer VCL templates that account for the caching behavior of each specific framework.

How to optimize specific Varnish settings

Improve Cache hit rate

Use the Varnish Configuration Language (VCL) to define rules for caching specific content. For instance, cache images and scripts for longer durations while refreshing dynamic content more frequently. Make sure only essential elements, like specific cookies and headers, affect the cache to maximize the number of requests served from cache.

Use grace and saint mode

Grace Mode: Allows Varnish to serve outdated content if the backend is slow or temporarily unavailable, ensuring a smoother user experience during high traffic or maintenance.

Saint Mode: Helps avoid downtime by skipping temporarily failing backends and testing others, enhancing site reliability.

Enhance backend performance

Varnish can continuously monitor backend health through health checks, automatically switching to healthy servers when necessary. Additionally, load balancing distributes the load across multiple backends to improve performance and prevent downtime.

Combell develops a Varnish solution for you

With years of experience optimizing load times and user experiences through caching technologies like Varnish, Combell is well-equipped to find the best caching solution for your website or application.

Our specialists will work with you to select and implement the optimal caching strategy tailored to your needs.