February 7, 2014 Leave a comment
Varnish is a reverse HTTP proxy, sometimes referred to as a HTTP accelerator or a web accelerator. It stores files or fragments of files in memory, allowing them to be served quickly. It is essentially a key/value store that usually uses the URL as a key. It is designed for modern hardware, modern operating systems and modern workloads.
To Note: Unless we use a separate application server instance for Varnish (which we should, for many good reasons!) this is technically not scaling (neither up, nor out), but having a good system architecture and basically being smart. However, due to the increase of load that can be handled by a single server, this could be referred to as scaling in some ways, as we are going to have much better overall performance from our system. This is really the result expected from scaling, and we end up with a system architecture that is ready to truly scale if necessary; however, it must be noted that better performance alone does not mean scaling.
At the same time, Varnish is flexible. The Varnish Configuration Language is lightning fast and allows the administrator to express their wanted policy rather than being constrained by what the Varnish developers want to cater for or could think of. Varnish has shown itself to work well both on large (and expensive) servers and tiny appliances.
Properties of Caching Reverse Proxy
A caching reverse proxy server typically has these properties:
- Local (close) to the web application
- Reduces the load on web/application servers for cacheable content
- Can cache many kinds of content, including dynamically-generated content
- Full control of cache flushes is with you
- The web application is ‘unaware’ of the caching taking place and does not need to be modified for the benefits of reverse proxy caching to be had
CDN (Content Delivery Network):
A content delivery network (CDN) is a system of distributed servers (network) that deliver webpages and other Web content to a user based on the geographic locations of the user, the origin of the webpage and a content delivery server. This service is effective in speeding the delivery of content of websites with high traffic and websites that have global reach. The closer the CDN server is to the user geographically, the faster the content will be delivered to the user. CDNs also provide protection from large surges in traffic.
Properties of a CDN
A CDN typically has the following properties:
- A set of “edge” servers which are located in various distinct geographic locations
- Suitable for slowly-changing content, because content propagation times are relatively high (hours)
- Owned by a third party
- Usually combined with custom DNS solutions (with low DNS TTL values) to effect the geo-direction
- Disconnected (by design) from the web application
- Typically serve “static” content such as images, Flash, video, etc.
- Cannot effectively cache dynamically-generated content
- URLs or applications often need to be modified to work with the CDN
Where to use Varnish Cache:
- If you need to reduce load on web or application servers for common content, use a caching reverse proxy.
- A caching reverse proxy reduces load on web/application servers and avoids unnecessary trips to a database or other content store for frequently-accessed content.
Where to use CDN:
- If your users are geographically spread, use a CDN.
- A CDN locates static content geographically close to end-users to avoid transmission delay
- If you need to address above mentioned issues, use both a CDN and Varnish as a caching reverse proxy.
- Varnish can sit in front of your site as an act as the caching gate keeper. A pull CDN will cache content/assets on the edge of the network. When a CDN node doesn’t have a copy of the page or asset it will call back to the origin (aka your server) for that item. If you don’t have Varnish in place and are using a CDN with many POPs (points of presence) your server will still get hammered with requests when adding new content.