Reputation: 48475
I can imagine two setups:
Load-balance then cache
+-- Cache server #1 (varnish) -- App server #1
/
Load Balancer (haproxy)-+---- Cache server #2 (varnish) -- App server #2
\
+-- Cache server #3 (varnish) -- App server #3
Cache then load-balance
+-- App server #1
/
Cache Server (varnish) --- Load Balancer (haproxy) --+---- App server #2
\
+-- App server #3
The problem with the first setup is that there are multiple caches, which wastes a lot of memory and makes invalidating cache more complicated.
The problem with the second setup is that there might be a performance hit and two single points of failure (varnish and haproxy) instead of just one (haproxy)?
I'm tempted to go with the second setup because both haproxy and varnish are supposed to be fast and stable: what's your opinion?
Upvotes: 45
Views: 21867
Reputation: 4450
Why not use 2 LB, the first LB can use balance uri
option, the second LB can use strategy of your choice (workload, round robin)
+-- Cache Server #1 --+ +-- App server #1
/ \ /
LB #1 --+ + -- LB #2 --+---- App server #2
\ / \
+-- Cache Server #2 --+ +-- App server #3
Scale where you need, just how much you need. If you find that you're not bottlenecked at Cache, simply remove LB#1 and place only one Cache server in front
Upvotes: 2
Reputation: 22681
Of course the first one !
With HAProxy configured for URI based balancing. (You need to distribute your Application User Session if you have ones in opposite than IP balancing mode).
Especially if you need HTTPS endpoint, since Varnish doesnt talk HTTPS.
Upvotes: 1
Reputation: 5012
I built a similar setup a few years back for a busy web application (only I did it with Squid instead of Varnish), and it worked out well.
I would recommend using your first setup (HAProxy -> Varnish) with two modifications:
keepalived
and a shared virtual IPbalance uri
load balancing algorithm to optimize cache hitsPros:
Cons:
Upvotes: 38
Reputation: 1759
Both have pros and cons. More in the blog article below, including the configuration for both HAProxy and Varnish: http://blog.exceliance.fr/2012/08/25/haproxy-varnish-and-the-single-hostname-website/
Baptiste
Upvotes: 11