Varnish caching layer vs load balancer

load balancingrackspace-cloudvarnish

We have around 10-15 different websites which at the moment are hosted on two Rackspace cloud servers with 4GB RAM. These two servers are totally independent of each other, we randomly choose a server for each new site.

We've recently launched a new site which is quite a memory hog, and has exhausted the memory on it's server several times since going up, causing it to crash. I'm looking into why this is within the site itself.
But also I think there's a lot I can do with the server architecture. There are two obvious things I could do…
Setup Varnish caching (the type of websites we have will benefit greatly from this).
And setup load balancing between the two servers.

So to do this, I've proposed we get one new cloud instance. Now my question is what to do with it…

1) Set this up as another LAMP server, and get a load balancer from Rackspace (which are quite cheap) to load balance between all three. Each running their own version of Varnish to cache the sites.

2) Set up the new box as a Varnish caching layer, and get Varnish to do the load balancing between the two we currently have.

I really like the sound of option 2, as all the caching would happen in one place. We could also do some cool stuff within Varnish like get it to serve cached pages if all servers were down, and have generally greater control.
Most of the website visitors are anonymous, so could be served a cached site. Most logged in users are editorial staff, so it's more important to prioritise high-availability.

But, in terms of maximising the available resource, I'm not sure what is the best thing to do.

Best Answer

Choose option 2 and then use a rackspace loadbalancer that does the following:

  • If varnish cache is up and alive direct all traffic to the varnish instance
  • If varnish is down load balance between the two remaining webservers

This prevents you from building a single point of failure but you need a reliable healthcheck in your loadbalancer configuration.