How to Reuse TLS Sessions in HTTP Clients
Cut handshake round trips with session tickets and TLS 1.3 PSK resumption, enable client session caches, and weigh 0-RTT replay risks.
On this page
Introduction
Every fresh TLS connection pays a handshake before application data flows: one round trip for TLS 1.3, two for TLS 1.2, plus certificate processing on both ends. For a short API request that is often more latency than the request itself, and it is CPU that both the client and the server spend on every connection that does not need to full-handshake. TLS session resumption lets a returning client prove a prior relationship instead of redoing the exchange: one round trip in TLS 1.2 with session tickets, and zero for the first application byte in TLS 1.3 early data. Connection pooling avoids handshakes by avoiding connections, but pools evict, burst, and get closed by servers, so resumption is the layer that keeps those unavoidable new connections cheap. This tutorial covers the mechanisms, the client configuration in three runtimes, server-side ticket key hygiene, verification, and the one sharp edge: 0-RTT early data can be replayed and must be constrained accordingly.
Resumption mechanisms
There are two mechanisms and a generation shift. Session identifiers, the original TLS 1.0 design, store session state server-side keyed by an identifier the client presents; they scale poorly because the server must remember every client, which is why stateless tickets took over. Session tickets, RFC 5077, encrypt the session state into a ticket the client holds and presents on return; the server decrypts instead of remembering, which scales horizontally as long as every replica can decrypt the ticket. TLS 1.3 replaces both with pre-shared-key resumption defined in RFC 8446: the server sends a session ticket derived from the handshake secret, and the client later proves possession of the shared secret. TLS 1.3 resumption also enables early data, colloquially 0-RTT: the client transmits application data in its first flight, eliminating the last round trip. That speed is the trap, covered later, because a network observer can replay the first flight verbatim. In every mechanism the security property is the same: resumption inherits the authentication of the original handshake, so the ticket itself becomes a secret worth protecting.
Enable the client session cache
The runtime defaults are uneven, and the difference is invisible without measurement, so configuration should be explicit. Node exposes session events on TLSSocket; capturing the session and offering it on the next connection is a dozen lines.
import { connect } from 'node:tls';
const sessionCache = new Map();
export function connectResumed(host) {
const socket = connect({ host, port: 443, servername: host,
session: sessionCache.get(host) });
socket.on('session', s => sessionCache.set(host, s));
return socket;
}
Higher-level clients built on the Node agent stack, such as got or undici with keep-alive, manage sessions automatically; the manual cache matters for custom protocol code. Go builds the cache into the transport and only needs it declared.
import "crypto/tls"
transport := &http.Transport{
TLSClientConfig: &tls.Config{
ClientSessionCache: tls.NewLRUClientSessionCache(256),
MinVersion: tls.VersionTLS12,
},
}
Python clients pool through urllib3 with sessions held per process; requests.Session and httpx.Client both resume automatically once a session object is reused. The universal rule across runtimes: one long-lived client per host, because per-request clients discard resumption state along with the pool.
Server-side ticket keys
Resumption only works when the server answering the second connection can decrypt the ticket the first connection issued. Behind a load balancer, that means every replica shares the ticket-encryption keys, or a client resumed onto a different replica full-handshakes anyway. Ticket keys must therefore be distributed and rotated deliberately: generated periodically, distributed to replicas through the configuration or secret store, and retained in a small ring of previous keys so tickets issued shortly before rotation still validate. The rotation period bounds how long a stolen ticket remains usable, which is the security purpose of rotating at all; a common choice is daily or more frequent for high-value properties. A secondary benefit of rotation discipline appears in incident response: revoking resumption for a suspect population means rotating keys, which is only possible if rotation is already an operational routine rather than an emergency hack. Capacity matters too: size the session cache or ticket volume for the returning-client population, because a cache that thrashes shows up as full handshakes under exactly the burst load where handshakes hurt most.
The 0-RTT replay problem
TLS 1.3 early data is fast because it is sent before the handshake completes, which means the server cannot know the handshake will complete, which means an on-path attacker can capture the first flight and replay it verbatim. The server sees a valid early-data request it has already processed. The defense is a protocol discipline, not a configuration flag: early data must be limited to requests where replay is harmless. Idempotent reads with no side effects qualify. A GET carrying no mutation is safe to replay twice. Anything with side effects, payments, state mutations, non-idempotent writes, must either wait for handshake completion or carry replay protection such as a one-time token the server records. Most HTTP client libraries default to not sending early data at all, which is the correct default. Enabling it for latency on read-heavy APIs is reasonable; enabling it broadly and hoping the application layer sorts out idempotency is how replay bugs ship. Servers can also mitigate with anti-replay windows that reject early data replayed within a short interval, but the robust property is end-to-end: treat 0-RTT bytes as possibly delivered more than once.
Verify resumption
Resumption is a silent optimization that fails silently, so verification belongs in both operations and tests. The openssl client prints the handshake summary directly.
echo | openssl s_client -connect example.com:443 -reconnect -brief 2>&1 \\
| grep -iE 'reused|protocol|cipher'
The first connection prints a full handshake and subsequent ones report Reused, which demonstrates ticket resumption against the live server. In Go, httptrace exposes the TLS connection state including DidResume. In Node, the secureConnect event can inspect the socket protocol and resumption through getSession presence. At the operational layer, servers export handshake counters, full versus resumed, and the resumed fraction should be watched: a drop after a deploy indicates ticket keys stopped being shared, and a sustained low fraction indicates client churn that connection pooling should be fixing instead. Verify after every certificate rotation and load balancer change, both of which quietly reset resumption paths.
Common pitfalls
- Per-request clients. New client objects discard session state, so every request full-handshakes despite resumption being enabled.
- Ticket keys not shared across replicas. Resumption succeeds only when the same replica answers twice; behind a balancer the resumed fraction stays near zero.
- Never rotating ticket keys. A stolen ticket stays valid until it expires; rotation is the revocation mechanism.
- 0-RTT on side-effecting requests. Early data is replayable; restricting it to idempotent reads is the only safe use.
- Assuming the library defaults. Some clients ship with resumption off or caches sized trivially; verify rather than assume.
- Blaming the client for server policy. Disabled resumption or rotated keys server-side produce the same symptom as a client bug.
Conclusion
TLS resumption removes most of the handshake cost that connection pooling cannot avoid: burst connections, evicted idles, and server-side closes. Enable the client session cache explicitly in every runtime, keep one long-lived client per host, and verify with handshake counters rather than trusting defaults. Server-side, distribute ticket keys across replicas and rotate them on a schedule, because rotation is both the security bound on stolen tickets and the only revocation path. Take the 0-RTT shortcut only for idempotent requests, since early data is replayable by design. Resumed handshakes will never appear in a feature list, but they show up in connect latency and CPU per connection, which is where they pay for the small amount of configuration they demand.
Sources: RFC 8446: TLS 1.3, Node.js TLS module docs, MDN: Transport Layer Security.
FAQ
- Is session resumption weaker than a full handshake?
- Resumption authenticates the cached session state rather than redoing the certificate exchange, so it trusts the earlier handshake. Keep session tickets encrypted server-side and rotate ticket keys to preserve the original security level.
- Does connection pooling make resumption redundant?
- Largely, for steady traffic. But pools evict idle connections, traffic bursts open new ones, and servers close connections, so resumption remains the cheap fallback that keeps those events from paying full handshake cost.
- Why does my client still full-handshake with a cache enabled?
- Common causes are ticket keys rotated server-side between attempts, no shared cipher or protocol version, resumption disabled on the server, or a cache that is per-process while connections come from a new one. Check the server configuration before blaming the client.
Report a problem with this articleOpens a pre-filled issue on GitHub.