At the core of Fastly is Varnish, an open source web accelerator that’s designed for high-performance content delivery. Varnish is the key to being able to accelerate dynamic content, APIs, and logic at the edge.
One of the major benefits of open source is being able to add to it and change it to suit our needs. Fastly uses a heavily customized version of Varnish 2.1, with added functionality. Our version of Varnish is optimized for large-scale deployments, since we have caches in many locations across the globe.
Fastly believes in the power of Varnish — our CEO Artur Bergman and engineer Rogier Mulhuijzen have contributed to parts of the base code, and continue to contribute to the project to this day. Rogier tells a great story about the first time he ever wrote VCL, which will also give you an idea of what Varnish is capable of.
Here’s why Fastly uses it.
Instant Purge for better performance
Varnish’s functionality gives Fastly its powerful instant purging capabilities, which in turn allow us to cache dynamic content. One of the ways that Fastly has customized Varnish is by extending it into a global caching network.
According to Varnish documentation, “Varnish has a modern architecture and is written with performance in mind. It is usually bound by the speed of the network, effectively turning performance into a non-issue.” Varnish software, combined with Fastly’s SSD servers, offer up to 12x the performance and capacity of traditional caches.
Varnish lets Fastly reverse proxy. If Fastly’s Varnish receives a request for customer content that is not already cached, Fastly will reach out to the customer’s origin servers and fetch the item requested, then send it to the user who has requested it.
Real-time data monitoring and management
Being built on Varnish also means Fastly can offer real-time monitoring of your content delivery. You can get per-second statistics delivered to you as a JSON feed to your dashboard, or as an in-browser two-minute rolling display. Real-time access logs can be streamed over syslog or to services like S3 or Logentries.
Custom Varnish Configuration Language (VCL)
You can configure Varnish using Custom Varnish Configuration Language (VCL) to define your caching policy. VCL functions more like a programming language than a configuration file, so you can create specialized configurations for caching dynamic content and running application logic on Fastly’s cache servers.
Fastly has a web interface that automatically generates VCL to your specifications. You can also write your own specially configured VCL, and can mix and match custom VCL with Fastly’s VCL. The VCL you write can be uploaded to Fastly caches and then activated. (If you’re interested in uploading your own custom VCL code, contact Fastly customer support.)
Varnish can load and unload VCL configurations on the fly, so changes to VCL can be deployed instantly. You don’t have to wait for maintenance windows or put up with server downtime.
The customer is always right
We use Varnish as the foundation for Fastly because of all its capabilities, but what it really comes down to is that we chose the right tool to create the CDN that suits our customers’ needs. Here’s what some of them have to say about Varnish:
“We know that we can route more API calls through Fastly if needed, and we can do a lot of tweaking using VCL to optimize some of those requests without changing the code. Fastly introduced us to the power and flexibility of Varnish. That's a big advantage we didn't necessarily anticipate, and it's a welcomed one!” — Konstantin Gredeskoul, CTO, Wanelo
“What’s dramatically different between using Fastly and other CDNs is that Fastly is not a black box we can’t control. Fastly is part of our infrastructure — it’s almost as if we were to spin up data centers all over the world just to be Varnish nodes; that’s Fastly. Fastly’s Custom VCL lets us leverage the power and technology of Varnish, giving us ultimate control and flexibility.” — Ross Paul, CTO, 1stdibs
“We started with an initial caching template to serve all of our static assets, which worked great. We then started developing new APIs on our side and doing more fine-tuning in the VCL to serve our assets in a better way, including caching dynamic content. We’re now seeing cache hit rates of 98-99% in our static assets.” — Harry Guillermo, Senior Developer, Fast Company