API Gateway TLS Performance: Handshakes, Session Reuse, and Measurement
API7.ai
September 8, 2026
The highest-value API gateway TLS optimization is usually to avoid unnecessary handshakes: keep client-to-gateway and gateway-to-upstream connections reusable, enable and verify session resumption where appropriate, and terminate TLS in a topology that does not repeatedly cross long network paths. Measure new and reused connections separately before tuning cryptography.
Security constraints come first. Keep supported protocol versions, certificate validation, and key protection at the required level; optimize within that boundary instead of weakening it for a benchmark.
Key Takeaways
- Separate connection establishment from steady-state request processing in every measurement.
- Reusing one authenticated connection usually saves more work than micro-tuning individual cipher operations.
- TLS 1.3 reduces handshake round trips compared with TLS 1.2 in common full-handshake cases, but network path and connection behavior still dominate many workloads.
- Session resumption must be tested across the real gateway fleet, including rotation and failover.
- TLS 1.3 0-RTT data has replay risk; do not enable it casually for state-changing APIs.
- Optimize both TLS legs when the gateway also uses HTTPS or mTLS to reach upstreams.
Build a TLS Cost Model
An HTTPS request through a gateway can contain two independent secure connections:
flowchart LR
C[Client] <-->|TLS connection A| G[API Gateway]
G <-->|TLS connection B| U[Upstream API]
Each new connection may require TCP establishment, a TLS handshake, certificate-chain transmission and validation, key agreement, and symmetric-key setup. DNS, routing, proxies, and packet loss can add time around those steps. Once a session is established, application records use much cheaper symmetric cryptography, but payload size and CPU still matter.
Ask four questions before changing configuration:
- What proportion of requests use a new client connection?
- Can the gateway reuse its upstream connections?
- How much of latency is network round-trip time versus gateway CPU?
- Are session resumptions actually succeeding across instances and deploys?
If nearly every request creates two new secure connections, cipher-level tuning is unlikely to fix the architectural waste.
Measure New, Reused, and Resumed Paths
Use a staging endpoint with the same certificate chain, gateway topology, protocol negotiation, and upstream TLS behavior as production. Test at realistic network distances; localhost hides handshake round trips.
Inspect one connection with curl
curl exposes useful timing fields:
curl --silent --output /dev/null \ --write-out 'connect=%{time_connect} tls=%{time_appconnect} start=%{time_starttransfer} total=%{time_total}\n' \ https://api.example.com/health
time_appconnect is elapsed time from start until the SSL/SSH handshake completes. Compare it with time_connect, time to first byte, and total time. One request is a diagnostic sample, not a performance result.
Inspect the negotiated session
openssl s_client \ -connect api.example.com:443 \ -servername api.example.com \ -tls1_3 </dev/null
Check the negotiated protocol, certificate chain, verification result, and application protocol. Do not use -verify_quiet or other output suppression as a substitute for actual verification.
Benchmark connection behavior explicitly
Run separate scenarios for:
- a new connection per request;
- many sequential requests on one persistent connection;
- realistic concurrent persistent connections;
- resumed sessions after an established session;
- instance rotation, scale-out, and failure;
- TLS at both the client and upstream legs.
Record handshakes per second, requests per connection, resumption success, CPU, latency percentiles, error rate, and bytes transferred. A load generator's default connection pool can accidentally turn a handshake test into a keep-alive test—or the reverse.
Optimization 1: Reuse Connections
Persistent HTTP/1.1 connections, HTTP/2 multiplexing, and HTTP/3 can carry more than one request on an authenticated connection. This amortizes TCP and TLS setup. The exact best protocol depends on client support, request pattern, head-of-line behavior, and network conditions; benchmark rather than assume.
Check every hop:
- client connection reuse and idle timeout;
- load balancer or CDN connection reuse to the gateway;
- gateway keep-alive pools to upstreams;
- upstream idle timeout and maximum requests per connection;
- intermediate NAT or firewall idle timeouts.
Timeouts must align. If an intermediary silently expires a connection before the client does, the next request may pay a reset, retry, and new handshake. Excessively long idle timeouts, however, retain sockets and memory. Choose them from reuse intervals and capacity, then observe the result.
Connection reuse also changes load distribution. A few long-lived HTTP/2 connections can concentrate work on fewer gateway instances. Ensure the load balancer and gateway fleet stay balanced under the actual connection model.
Optimization 2: Prefer Current Protocols Without Weakening Policy
Apache APISIX 3.18 supports TLS 1.2 and TLS 1.3 by default according to its security threat model. TLS 1.0 and 1.1 are considered weak and are not enabled by default. Keep protocol decisions aligned with client compatibility and your security requirements.
TLS 1.3 simplifies the handshake and, in a typical full handshake, removes a round trip compared with TLS 1.2. It also defines PSK-based resumption. That can reduce setup work, but only if clients resume successfully and the gateway instances can honor the issued tickets or state.
Do not present TLS 1.3 as a fixed percentage latency improvement. A nearby client, a reused connection, or a slow application can make the difference negligible; a distant client opening frequent new connections can make it material.
Optimization 3: Verify Session Resumption Across the Fleet
RFC 8446 defines TLS 1.3 session tickets that a client can later use as a pre-shared key. Resumption can reduce the work of reconnecting without keeping one connection open forever.
Fleet operation creates important questions:
- Can a ticket issued by one instance be used after the next connection reaches another instance?
- How are ticket-encryption keys or server-side session state rotated and protected?
- Does rotation preserve an acceptable overlap without extending key lifetime excessively?
- What happens during deploy, scale-out, regional failover, or certificate rotation?
- What percentage of eligible handshakes actually resume?
Do not trade away key isolation merely to maximize a benchmark. Sharing ticket keys across too broad a fleet increases the effect of key compromise. Choose the scope and rotation design with the security owner, then measure the operational hit rate.
Treat 0-RTT as a separate security decision
TLS 1.3 early data, commonly called 0-RTT, is not the same as ordinary session resumption. RFC 8446 explains that 0-RTT lacks the same replay guarantees as normal application data and requires anti-replay handling. Network attackers can cause accepted early data to be replayed in ways the TLS layer cannot fully prevent for the application.
Do not use 0-RTT for creating orders, charging payments, changing access, or other non-replay-safe operations unless an application-specific profile and tested anti-replay design make the semantics safe. You can gain most connection-efficiency benefits through reuse and ordinary resumption without sending application mutations as early data.
Optimization 4: Keep Certificate Delivery Efficient
Certificate chains are sent during full handshakes and affect bytes, parsing, and validation. Use the correct chain: include required intermediates, omit unrelated or duplicate certificates, and test with the trust stores of supported clients. A smaller but incomplete chain is not an optimization.
Certificate and key choices are compatibility and security decisions as well as performance choices. Compare them only against supported clients and compliance requirements. If you offer multiple certificate types, confirm that selection, SNI, stapling behavior, and monitoring work on every gateway instance.
Automate renewal and alert on expiration. A fast handshake that intermittently serves an expired, mismatched, or incomplete certificate is an outage.
Configure an APISIX SSL Resource
Apache APISIX represents downstream certificates as SSL resources. The current Admin API documentation supports certificate, private key, SNI names, and an ssl_protocols array.
The following APISIX 3.18 example is a parseable template. Replace both PEM placeholders with real material from a secret-management workflow; do not commit private keys to source control.
{ "cert": "-----BEGIN CERTIFICATE-----\n<server certificate and intermediates>\n-----END CERTIFICATE-----", "key": "-----BEGIN PRIVATE KEY-----\n<private key from secret storage>\n-----END PRIVATE KEY-----", "snis": ["api.example.com"], "ssl_protocols": ["TLSv1.2", "TLSv1.3"] }
Apply the file through the Admin API in a controlled environment:
curl "http://127.0.0.1:9180/apisix/admin/ssls/api-example" \ -X PUT \ -H "X-API-KEY: ${admin_key}" \ --data-binary @ssl.json
This resource selects protocols; it is not a complete performance configuration. Connection pooling, worker sizing, listener settings, session behavior, and any load balancer in front depend on the deployment. Confirm them against the APISIX and infrastructure versions you run.
Optimize the Upstream TLS Leg Too
When APISIX proxies to HTTPS, client-side handshake measurements show only half the path. A gateway that reuses downstream connections but creates a fresh upstream TLS connection for each request can still spend significant CPU and latency.
Measure:
- upstream connection creation and reuse;
- upstream TLS handshake latency and failures;
- upstream certificate verification and SNI correctness;
- keep-alive pool hit rate and idle eviction;
- mTLS certificate lookup and rotation behavior;
- connection concentration on upstream nodes.
Do not disable upstream certificate verification to improve latency. Fix trust-chain, naming, or connection-pool problems instead. If strict identity between gateway and service is required, mutual TLS adds client-certificate work and operational state that should be included in the benchmark.
Separate CPU Saturation from Network Latency
Handshake latency can rise because packets travel far or because gateway workers are CPU-saturated. The remedies differ.
Network-dominated signals include stable gateway CPU, latency proportional to client distance, and improvement from fewer round trips or nearer termination. CPU-dominated signals include rising run queues, handshake throughput flattening, and latency increasing across all client regions as connection churn grows.
Profile with production-like certificate algorithms, plugin chains, and traffic mixes. Avoid measuring TLS on an otherwise empty gateway and applying the result to one performing authentication, logging, compression, and transformations.
Scale-out can help CPU capacity but can reduce resumption if new instances cannot use prior session state. Validate both effects together.
Roll Out with Guardrails
- Capture a baseline for new, reused, and resumed connections.
- Change one layer at a time: client reuse, edge-to-gateway reuse, gateway-to-upstream reuse, protocol, or session configuration.
- Compare latency percentiles, CPU per request, handshake rate, resumption success, connection errors, and certificate failures.
- Canary across real client implementations and network paths.
- Test rotation, instance replacement, and failover.
- Keep a rollback path that does not restore deprecated protocols or unsafe verification settings.
Watch error budgets as well as averages. A change that improves median handshake latency but causes a small group of important clients to fail is not a successful optimization.
TLS Performance Checklist
- Are new connections and persistent connections measured separately?
- How many requests does each client and upstream connection carry?
- Are TLS 1.2 and 1.3 choices compatible with policy and supported clients?
- Is session resumption succeeding after load balancing, deploys, and rotation?
- Is 0-RTT disabled or restricted to operations proven safe against replay?
- Is the certificate chain complete and no larger than necessary?
- Is upstream HTTPS or mTLS included in the cost model?
- Are CPU, network distance, and application latency separated?
- Have failover and certificate renewal been tested?
Summary
API gateway TLS performance is primarily a connection-lifecycle problem. Measure the full and steady-state paths, reuse connections on both sides of the gateway, validate TLS 1.3 and session resumption under the real fleet topology, and keep 0-RTT replay risk separate from ordinary resumption. APISIX can terminate modern TLS and manage certificates, but the best settings depend on client compatibility, topology, security policy, and observed connection behavior.
FAQ
Is TLS 1.3 always faster than TLS 1.2?
It can reduce handshake round trips in common full-handshake cases, but the observed benefit depends on network distance, connection reuse, client support, resumption, and application latency. Measure the actual path.
Should an API gateway enable TLS 1.3 0-RTT for better performance?
Not by default. Early data has replay risk and requires an application-specific safety design. Ordinary connection reuse and session resumption usually provide safer first optimizations.
Does terminating TLS at the gateway remove all TLS cost?
No. The gateway still performs downstream TLS, and it may establish another TLS or mTLS connection to the upstream. Both legs belong in the capacity and latency model.
Next Steps
Baseline full, reused, and resumed connections, then verify the APISIX SSL resource fields supported by your release. For managed certificate and policy operations around Apache APISIX, explore API7 Enterprise.