I intend to run a few tiny ARM "physical cloud" servers behind a load balancer(either HAProxy or nginx itself), but i can't decide where to put Varnish in the whole mess.

I can either have it on each instance, doing the job locally, but seeing that the contents will be the same it seems kind of a waste.

I can also have it on the same instance as the load balancer - but that creates the question - in front of or behind it? To me, logically, it should be in front of - if it can fetch the page from cache, there's no need to bother the load balancer with the request. And, i can even remove the load balancer and use Varnish to round robin between the backend instances.

But i found a multitude of different solutions online, without any (recent) benchmarks or pros/cons of either variant, so i can't decide are there any problems with my "ideal" scenario (Varnish as a load balancer and caching engine).

So - is it feasible to use Varnish as a load balancer? If not, should i put it in front of or behind the load balancer itself?

1 Answer 1


Caches traditionally go in front of the load balancer, as the load balancer exists to mitigate slow application servers and the cache seeks to mitigate running the application server at all. The downside is that a Raspi-esque cluster might not have a lot of resources to maintain large caches.

The time you want to put Varnish behind the load balancer is when you need to spread a cache across multiple machines, either for fault tolerance or to mitigate storage requirements. For example a load balancer set to hash based on request URL is able to make sure all requests for "cat" go to machine A, while requests for "dog" go to machine B, in case you want to rely on a large cache but can't fit it all on one of the tiny ARM devices.

  • Another good reason to put Varnish behind the load balancer is SSL termination which AFAIK, Varnish still doesn't do. Jan 22, 2017 at 22:58
  • He's using nginx, which already acts as an SSL terminal.
    – Skrylar
    Jan 24, 2017 at 14:37

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .