I'm trying to understand how the loadbalancing in HAProxy works so that I can do some capacity planning. So which one is the right way the HAProxy load balancing works?
Scenario A: Request from Client was sent to HAProxy, Haproxy forwarded the request to the available webserver which in this scenario Webserver1. The webserver1 respond to the request and return the requested page directly to Client's browser.
Scenario B: Request from Client was sent to HAProxy, Haproxy forwarded the request to the available webserver which in this scenario Webserver2. Webserver2 respond to the request by sending the page back to HAProxy and HAProxy pass the request back to Client's browser.
Also, can this setting works? Internet facing NIC in HAPRoxy is using the public IP where the internal facing NIC for HAProxy use private IP and so does the webserver1 and webserver2. They both use private IP.
Last question. What kind of load balancing scenario does HAProxy support other than Round Robin? What I'm trying to accomplish is, when client is connected the first time to webserver1, I'd like to keep that connection for that client until the session is expired or terminated. Any suggestion on how to accomplish that?
Please advise?
Many thanks for all of your advise.
Scenario B. HAProxy creates a TCP connection to the backend to send the client's request, the backend responds to HAProxy, then HAProxy sends the request to the client. The client never has a TCP connection to the backend, so there's no direct communication possible between them.
Yes, that can work.
What you're looking for is called sticky sessions, see this question for an example.