I have a client that uses TCP/TLS to communicate with a load-balanced pool of back-end servers.
The protocol is a streaming protocol, with no notion of requests and responses.
Once a connection is established with one of the back-end servers, say S1
, can I assume that all subsequent TCP/TLS packets from the client would continue to flow to S1
regardless of the load-balancer type chosen e.g. Application and Classic load balancers in the EC2 world, and perhaps even the Network load balancer?
It is okay if post disconnection, a new connection from this client gets load-balanced to another back-end server S2
.
Note: Essentially, I do not know for sure if all load-balancers do DNAT, in which case S1
once chosen by the load balancer would stick around for the client for the lifetime of the connection.
A TCP connection gets initially established (TCP handshake) with a single server and this connection endpoint has the information about the current state of the connection.
If a load balancer would send different packets of the same connection to different upstream servers, then only a part of the packets would arrive at the upstream having the TCP connection state. From the perspective of this upstream this would look like a connection with packet loss and thus the server could not proceed in handling the payloads. Similar, the other upstream would not have the connection state and thus discard/reject these unexpected packets.
In other words - it would simply not work. But since load balancers actually work you can count on them properly distributing any packets, i.e. keeping state of connections and having only a single upstream for a connection.