June 7, 2021
2 min read time

Two Minute Tech Tuesdays - Varnish High Availability (VHA)

two_minute_tech_tuesdays_vha

In this episode we’ll be talking about Varnish High Availability.

Varnish High Availability, or VHA as we call it, is a replication tool that is designed to synchronize caches across multiple servers, and as the name implies, high availability is the obvious benefit.

 

 

This means when a server is no longer available, another Varnish node can take over. Because the cache were synchronized, a much better hit rate will be yielded. You will not only use VHA in case of an outage, it's also useful when you have multiple Varnish nodes sitting behind a load balancer.

When that load balancer happens to select another node, It will still return a cache hit because of the cache synchronization. And if the cost of the cache miss is too high, this is a very good tool to have in your tool kit.

In terms of efficiency, VHA will result in:

  • 50% more hits on a two node cluster
  • 66% more hits on a three node cluster
  • 75% more hits on a four node cluster

 

VHA is entirely written in VCL and uses a collection of VMODs. It also leverages the Varnish Broadcaster for message exchanges. Varnish Broadcaster is also part of the Varnish Enterprise suite of tools. The inventory of nodes that need synchronization are kept in the nodes configuration file (nodes.conf), which is also part of the Varnish Broadcaster. 

All messages are encrypted and VHA is highly configurable. In case of frequent inventory changes, Varnish auto-discovery will keep your nodes.conf configuration file up to date. 

 

The replication flow goes as follows:

  1. When Varnish receives an object that it needs to store in cache, it will also send a broadcast message to the other nodes. The sender of this message is then called the origin node, whereas the receivers are considered the peers. 
  2. When a peer node receives a broadcasting notification, it will request the actual content from that origin Varnish node,
  3. The origin Varnish node will then send the actual payload to the peers, which it will store in cache.

 

Because VHA is written in VCL, getting started is super easy. It's just a matter of including the bootstrap file which is shipped with Varnish Enterprise, setting the secret token for replication in the VCL init sub routine and calling vha6_token_init to start replication, and the rest happens automatically, behind the scenes. 

 

Next episode is coming next Tuesday where we’ll cover another technical topic in two minutes or less. Stay tuned! 

 

varnish_6_by_example_download