A Layer 4 load balancer selects a target for a transport connection or flow. A Layer 7 load balancer can select a target for an application request, such as an HTTP request for /api/orders.
Choose the routing behavior your application needs, then check TLS trust, client identity and recovery separately. A working health check cannot tell you whether an interrupted order was saved or whether a reconnect will restore a user's session.
Follow a connection through Layer 4
In the upper diagram below, a client connects to a virtual IP on TCP port 443. The balancer selects a backend. With TLS passthrough, that backend holds the certificate and handles the TLS handshake. The balancer forwards the encrypted stream without reading the HTTP path.
For AWS Network Load Balancer's TCP routing, packets from one connection stay with its selected target for the life of that connection. A new connection can select another target. AWS documents the distinction between this flow selection and Application Load Balancer's request routing in its request-routing guide.
This matters for connection pools. An application sending many requests over a small pool of persistent TCP connections gives a connection-level balancer few opportunities to distribute work. Adding a backend does not move existing connections onto it. Test with your real connection reuse and request mix before judging whether traffic is balanced.
Transport balancers can proxy connections or forward packets. Source addresses and return paths depend on the implementation. This approach often fits PostgreSQL, SMTP and custom TCP services; UDP support depends on the product and listener. The diagrams here describe TCP, not every transport protocol.
Route HTTP requests at Layer 7
The lower diagram shows an HTTPS reverse proxy. The client connects to the balancer, which terminates TLS and reads the HTTP request. Rules send /api/* to an API target group and other paths to the web application. The balancer uses a separate connection to the backend, optionally with TLS.
A client connection and a backend connection are separate resources. AWS ALB can reuse backend connections for requests from multiple clients. Its HTTPS listeners also support multiple concurrent HTTP/2 requests on one client connection. Those requests still need application routing; counting connections alone will miss the amount of work they carry. See AWS's HTTP connection behavior and listener protocols.
An upgraded WebSocket connection stays with its selected backend. Moving later HTTP requests to another server does not migrate an established socket or its application state. Plan how the client reconnects and resumes work. If your application relies on a particular server between requests, review its session-affinity requirements.
Where TLS ends, and who is trusted
TLS termination does not define the routing layer. AWS NLB supports TLS listeners that decrypt traffic without providing HTTP path routing. For TLS passthrough, its TCP listener can forward the encrypted connection to the target. These are separate NLB listener choices.
Write down both hops: client to balancer, then balancer to application. For each TLS hop, name the certificate owner, the verifier and the expected server identity. If client certificates are required, identify which component authenticates them and how the application receives that identity.
Backend encryption needs a closer look. AWS ALB establishes TLS to HTTPS targets but does not validate their certificates. NGINX's HTTP proxy module has upstream certificate verification disabled by default; its certificate-verification settings control that behavior. An HTTPS backend URL alone therefore does not prove the proxy checks the backend's certificate identity. Check the actual product settings and network trust boundary.
The following is a design worksheet, not a benchmark or a promise that every product supports each option.
| Need | Check before choosing |
|---|---|
| HTTP paths | The proxy can decrypt HTTPS and match the required host or path. |
| TLS passthrough | The application owns the certificate and TLS session. |
| Backend trust | The design defines certificate validation or the documented network trust model. |
| Long sessions | Socket recovery and application state survive a reconnect. |
| Client IP | The target receives a verified address through an agreed mechanism. |
Keep client identity across the proxy
A backend may see the balancer's address instead of the client's. AWS ALB normally appends the client address to X-Forwarded-For, but it also supports preserving or removing that header. AWS warns that entries are trustworthy only when added by secured systems. Read the ALB header behavior before using these values for logs, rate limits or access decisions.
Configure the application to trust only the proxies it expects, and restrict direct access to the origin. A client can send its own forwarding header. Selecting the first address in an arbitrary incoming list is not a safe way to establish identity.
For NLB, source-IP preservation depends on target type, protocol and network path. TCP and TLS target groups using IP targets have it disabled by default. Proxy Protocol v2 is another option, but the receiving server must parse its header; enabling it on an incompatible backend can break traffic. AWS documents both IP preservation and Proxy Protocol. Test the address your application records, including any CDN or additional proxy in front.
A failed request may already have changed data
Consider this hypothetical failure: an API commits an order, then its connection closes before the response reaches the client. A timeout leaves the client uncertain about the result. Sending the same operation to another healthy server can create a duplicate unless the application has a way to recognize it.
HTTP's idempotency rules describe when repeated requests have the same intended effect. The standard prohibits a proxy from automatically retrying non-idempotent requests. For writes, define the application's duplicate-detection and result-retrieval behavior before enabling automatic retries.
Proxy settings also limit what can be recovered. NGINX's upstream retry rules normally prevent retrying a non-idempotent method after sending it upstream. It also cannot switch upstreams to repair a response once data has been sent to the client. Check request buffering, retry conditions and attempt limits for the product you operate. Bound retries within the client's deadline, and record each attempt so a final success does not hide repeated failures.
Separate health failure from planned draining
The traffic protocol and the health-check protocol are independent. NLB supports TCP, HTTP and HTTPS checks, including separate checks for UDP services. Its health-check documentation also describes fail-open behavior when all targets fail checks. A healthy TCP listener proves much less than a successful application operation. Use a readiness signal that reflects the work you need, with explicit failure and recovery thresholds.
A planned deployment should stop new work and allow existing work to finish before stopping the process. ALB's deregistration delay supports that sequence. Keep the application alive during the drain and decide what happens when the deadline expires.
An unhealthy target is a different event. NLB has a separate setting for terminating established connections to unhealthy targets, enabled by default. Disabling it allows existing connections to remain while new ones stop, subject to its health and fail-open behavior. Neither setting transfers a session to another backend. A crashed process still needs client recovery.
Run a bounded staging exercise
Use isolated targets and disposable data. Record the deployed settings first, choose an abort condition and keep enough healthy capacity for the test load. The worksheet below describes proposed tests, not measured results.
| Exercise | Evidence to collect |
|---|---|
| Reuse a connection | Backend IDs for repeated requests, then for fresh connections. |
| Fail one check | Time of health change; new-request errors; fate of open sockets. |
| Drain a target | Last new request, last completed request and process exit time. |
| Interrupt a write | Stored result and retry attempts; proof that one intended write occurred. |
| Resume service | Recovery threshold, resumed traffic and remaining client errors. |
Run each case with the protocols your clients use, including long responses or WebSockets where relevant. Compare the same payloads, concurrency and TLS configuration when measuring latency. The layer number supplies no universal performance result.
Keep an external probe on the public route during the exercise. Compare it with backend logs so you can distinguish DNS or TLS failure from application failure. Our health-check guide explains how to separate readiness checks from those public-path checks.