HAProxy community

Loadbalancing TCP requests

My set up is with one client node and two back end nodes and a HAProxy server sitting between the client node and the back end nodes. The client node sends requests to the HAProxy and my expectation is the requests will be load balanced as per below configuration. Which is first request goes to server1 and the next one goes to server2 and so on.

backend tcp_back
mode tcp
balance roundrobin
option tcp-check
tcp-check connect
option tcpka
timeout connect 500
timeout client 50000
timeout server 50000

server server1 10.10.10.1:3001 check
server server2 10.10.10.2:3001 check

But the problem is if I send back to back requests from my client node, all of those requests will end up in one backend server. But if I wait for some time ( I believe if I let the session expire by waiting for the timeout server setting) and then make a request, it will go to the second server. Could some one explain what happens here?

There is no concept of requests or transactions when you are using tcp mode.

A TCP connection is established on the frontend and a corresponding TCP connection is established on the backend between haproxy and the backend server.

Whatever your application does within that TCP connection, stays within that TCP connection. Haproxy has no way to know.

Unless your application establishes a new TCP connection, load-balancing will not occur.

Thank you @lukastribus for your reply.