Varnish as load balancer

Christoph Handel varnish at
Mon May 18 11:33:31 CEST 2009

On Mon, May 18, 2009 at 11:13:24AM +0200, Tollef Fog Heen wrote:
> ]] "Carlos Oliva G." 
> | In the current setup I'm skipping Lighttpd altogether and began using  
> | Varnish as a load balancer altogether as well, with the 'directors'  
> | feature. However I'm still missing the last bit of the requested  
> | functionality that is to evenly balance all the requests from  
> | 'anonymous' users that aren't registered/logged into the system (which  
> | I am already identifying in the sub_rcvd function of my VCL), but for  
> | registered users to preserve their session by redirecting them always  
> | to the same backend server. I know I can create a 'hash' using some  
> | relatively unique values, as the originating IP address + the User  
> | Agent and a session-dependent cookie value, but what I don't know is  
> | (if possible), how to use this hash to determinate to what backend  
> | server to direct the request to.
> We currently don't have a hashing load balancer (which is what you seem
> to want).  (Patches accepted, or Redpill Linpro can get you a quote on
> how much work it is to develop it.)
> What you could do is have the backend set a cookie with its name when
> the user logs in, and then choose backend depending on cookie value.
> Another alternative is to use nginx or similar as Varnish' backend and
> let that do the hashing and load balancing.  I have been told it's quite
> good, but I don't have experience with it myself.

you could take a look at haproxy (

copes with pretty high loads and allows you to inject cookies for
sticky sessions.


More information about the varnish-misc mailing list