Advanced Details of Load Balancers (L4 vs L7) 00:00:01 Follow one encrypted connection A client opens a secure connection to a virtual address. Watch the transport balancer record a backend for that flow, without needing the encrypted application path. Client 203.0.113.9 opens a TCP connection to port 443 on the virtual address. The balancer uses address, port and protocol. The path, headers and cookies are encrypted and unread. The flow is new. Its hash gives Server 1, and the choice goes into the flow table. NAT changes the destination to 10.0.0.1. The whole connection will follow. The reply comes back through the balancer, which restores its own address as the source. This example uses address translation and a connection table. Other layer-four designs may forward differently, but their balancing decision is still made at the transport-flow level. 00:00:56 Follow one readable application request Now a proxy terminates the client's encrypted session. A catalog request contains a host and a path. Predict which newly readable information can select a different backend service. GET /api/users for api.example.com, inside TLS. The balancer holds the certificate for the host and decrypts. This example uses TLS 1.3. It parses the method, host, path, headers and cookies. The path starts with /api, so the API server is the right place. Add X-Forwarded-For with the connection's own address, then send the request on an open connection. The response is compressed with gzip on its way back. It was forwarded, so it was not a cache hit. The proxy can route individual requests and reuse upstream connections. Certificate handling, trusted client identity propagation and any encryption on the upstream leg are independent design decisions. 00:01:56 Which fields can steer the route Place addresses, port, hostname, path and cookies on the workbench. Distinguish fields visible during connection setup from HTTP fields available after appropriate TLS termination. Both balancers see addresses, ports and protocol. The Host header is encrypted, but a layer 4 balancer may peek at SNI. Layer 7 reads the header. The path is inside the encrypted request. Only layer 7 sees it. The cookie is a header, so the same holds. That is why cookie stickiness needs layer 7. Some proxies inspect available handshake metadata for limited routing. Reading an HTTP cookie or path requires access to application data, and encrypted handshake metadata can constrain name-based inspection. 00:02:44 Three connections carry twelve hundred requests One client sends a thousand requests a second. Two others send a hundred each. Hand one connection to each backend and predict whether the workers share equal request volume. Client A sends 1,000 requests a second. B and C send 100 each. Each server gets one connection. That looks fair, but Server 1 does ten times the work. Open connections do not move. A new server only receives new connections. The balancer reads each request and spreads 1,200 evenly: 400 each. Per-request routing could divide twelve hundred independent equal-cost requests into four hundred each here. A long-lived stateful stream can place stricter limits on redistribution. 00:03:29 Put a transport balancer in front of two proxies Clients see one transport address. Behind it two application proxies route requests to users or orders. Trace the failure of one proxy from the perspective of old connections and new ones. Clients only know the layer 4 address. The first tier sends connections to both proxies. Each proxy ends TLS and routes by path to the users or orders service. Health checks fail, and new connections go to proxy 2. Connections on proxy 1 break and clients reconnect. Health checks can direct new connections to the surviving proxy. Client recovery and idempotent retry policy determine what happens to in-flight work on the failed path.