The TCP handshake · Lesson 5 of 8 · 3 min read
Latency: handshakes, TLS and connection reuse
Counting round trips
| Connection | Round trips before the first request byte |
|---|---|
| TCP + HTTP (plain) | 1 |
| TCP + TLS 1.2 | 3 |
| TCP + TLS 1.3 | 2 |
| TLS 1.3 resumption with 0-RTT | 1 (data in first TLS flight) |
| QUIC (HTTP/3) new connection | 1 (transport + TLS combined) |
| QUIC 0-RTT resumption | 0 |
With 150 ms RTT, a fresh TLS 1.2 connection costs ~450 ms before the request — which is why every hop should reuse connections:
- HTTP keep-alive and HTTP/2 multiplexing between clients and load balancers.
- Load balancers keep connections to targets open and reuse them across client requests (ALB does), avoiding a handshake per request.
- Connection pools in apps for databases and downstream APIs.
- TLS session resumption for repeat clients.
- CDNs terminate TCP/TLS close to the user (short RTT), then reuse long-lived connections to the origin.
Enlarge diagram
Swipe sideways to see all of it, or tap to open it full screen.
Idle timeout mismatches: the 502 classic
A load balancer reuses an idle connection to a target at the exact moment the target's keep-alive timeout closes it → the request hits a closed connection → intermittent 502. Rule: the backend's keep-alive timeout must be longer than the load balancer's idle timeout (ALB default 60 s → set the app to e.g. 65–75 s; Node.js's default keepAliveTimeout of 5 s is a famous offender).