Varnish Your Cash!

July 05, 2013
Senior Dev Ops Engineer

If you are interested in learning about caching content, gaining performance and a lot more cool stuff through Varnish, this is it!

Kevin Mitchell?

A couple of months ago at ID, as I was assisting my colleague Kevin Mitchell (no, not the major league left-fielder. See Figure 1), on a project involving optimizing Magento’s performance, and the subject of caching – and more precisely Varnish – became a topic of conversation.

Figure 1 – Kevin Mitchell, famous Infield Digital Magento developer

As I dived deeper, I grew more interested in this easy-to-use, high-performing, magnificent piece of technology. In the next few paragraphs I’ll briefly introduce you to caching, then we’ll fly over Varnish and finally, I’ll give you a link to a document I’ve compiled for those that would like to get started on Varnish the easy way.


As you build a website, there are several questions that come up. What kind of structure do I want? Am I building a commerce site? What programming language do I want to use? Do I need a database? What do I need in terms of web servers?As you answer these questions, you lay the foundation of your site, then debug, test, and repeat the cycle again and again. As you get closer to the final product, whether you are using a special framework, a cutting-edge programming language, or a killer implementation of a specific algorithm, there comes a moment when you tilt your head and say, “This is not fast enough!”

Without further ado, you minify your Javascript, your CSS, and review your SQL requests to see if you can speed up the entire system. You may see some small improvement (or not), but often it’s still not fast enough. At the heart of the problem is that your site is serving content that’s requested by hundreds of users. For example, let’s say Bob goes to the page “” and immediately after, Alice visits the same page. This means that two requests have been made to the same page. If you multiply this by the number of people who visit your site, you start to understand why your content is delivered slowly.

The solution to this conundrum is to reduce the number of requests to the web server and still deliver the requested content. The generic term for this concept is “caching,” which we’ll illustrate as an HTTP accelerator. Let’s say our dear friend Bob hits “” and the request goes to our server which looks to see if the page is in the cache. In this case it is not, so it transfers the request to the web server which then builds the page. Before the page is sent back to Bob, it is stored in the caching system. A bit later Alice goes to the same page and the request is sent to the server that hosts our site which checks our caching system to see if someone has requested the page or not. Since Bob had previously requested it, instead of going to the web server to re-build the page (which would slow down our site), the server quickly delivers the page that was previously stored in the cache.

“A picture is worth a thousand words” right?! Let’s have a look:

Figure 2 – Concept of caching.

Now that I’ve introduced and illustrated the concept of caching as an HTTP accelerator and your eyes are nearly bleeding due to my lack of artistic talent (Figure 2), we can get to the point. Our site in place, code and database optimized, we begin our journey in the land of Varnish caching.


What is it?

Varnish Cache is a web accelerator, sometimes referred to as an HTTP accelerator or a reverse HTTP proxy, that will significantly enhance your web performance (Figure 3).

How does it work?

Install Varnish Cache in front of any web server that speaks HTTP and configure it to cache the contents. The result? Varnish will speed up the delivery of your web content (Figure 3).

Figure 3Varnish in action.

What are the advantages?

Flexibility – The Varnish Configuration Language (VCL) is lightning fast and gives web administrators the freedom to express their desired policy rather than being constrained by what the Varnish developers can do, have defined, or want to cater to.

Dynamic content – Varnish will help you deliver all the dynamic content you want without the web performance suffering.

UX and customer conversion – A faster, more reliable website will have a positive effect on your customer satisfaction, conversion rate and revenue.

Fast Return On Investment – Once you have an optimized version of Varnish up and running, you can reduce the number of web servers supporting your website giving you lower maintenance costs, a smaller carbon footprint and a quick ROI.

What’s next?

Since the objective of this article is to whet your appetite for Varnish, I won’t delve into the technical world of Varnish.  But if you want an easy and fast way to get started with Varnish, I wrote a short document (17 pages) that should help you ease your way into your Varnish career. Hope you enjoy reading it as much as I did writing it!

A quick Varnish resource 

Of course, I recommend the official Varnish documentation. But, for those of you who aren’t as invested, the official documentation might scare you away with its length. Consequently, I put together a document to enable you to get started and have fun with Varnish as fast as possible, so have a look!