The best model for load balancing with multiple services in haproxy

haproxy

The options I can think of are:

1) Have multiple frontends each with a different port.

2) Have multiple frontends each with a different hostname but the same port.

3) Have a single frontend with the same hostname and same port using ACLs to route based on URI

We have currently got 12 distinct services (micro services) that we'd like to load balance. It may grow a bit.

What are the compelling reasons to choose any of these approaches?

Best Answer

1) Have multiple frontends each with a different port.

To me, this just seems a little sloppy. Lumping multiple web services onto one IP address with different ports only seems useful to me if you don't have the IP addresses to spare (in which case you probably have other issues)

2) Have multiple frontends each with a different hostname but the same port.

This seems like the best choice to me. Have each frontend bind to a different IP address, and then each using the appropriate backend(s).

3) Have a single frontend with the same hostname and same port using ACLs to route based on URI

This would also work, but remember that if you have a single frontend, they'll end up sharing some resources. For instance, if you set a "maxconn" parameter on the frontend, and then there are many concurrent connections to one of the services, requests for the other services could end up getting queued.

Ultimately, I think it really comes down to how much in common the separate frontends have with each other, and if you want their connection limits to be shared. If the services are all tightly knit, and function nearly identically, you might choose #3, but if they aren't really related, I think #2 would be your best bet. At the very least, you can get them set up on individual IPs now, and have a frontend that binds to multiple IP addresses, so it's easy to split it into multiple frontends later on down the road.