The Hidden Cost of DNS and TLS in API Calls
Understand where connection setup time goes and how keep-alive, session resumption, and HTTP/2 change the picture.
When an API call feels slow, attention usually goes to server code. But for short requests, a large part of the elapsed time can happen before the server sees the request at all: DNS resolution, TCP handshake, and TLS negotiation.
The sequence before your request body arrives
A fresh HTTPS call typically follows this order:
- Resolve the hostname to an IP address through DNS.
- Open a TCP connection with a three-way handshake.
- Negotiate TLS, including certificate exchange and key agreement.
- Send the HTTP request.
- Wait for response headers, then read the body.
Steps one through three are setup cost. They are paid once per connection, not once per request, if the client reuses connections.
Why short requests suffer most
If your endpoint normally responds in 20 ms but each call spends 80 ms on setup, setup dominates. The same 80 ms is less visible on a response that takes two seconds. This is why a high-frequency service with tiny payloads can feel slower than a heavier service that keeps connections warm.
Browsers and HTTP clients keep a pool of open connections. When the pool is exhausted or connections are closed by an intermediary, new calls pay setup again. Check whether your server closes idle connections too aggressively, or whether a proxy forces renegotiation.
DNS details that matter
DNS results are cached at several layers: operating system, resolver, and application. A low TTL makes changes propagate faster but increases lookups. A very high TTL can strand clients on an old address after a migration.
For services that call many hostnames, pre-resolving or warming connections at startup can avoid a burst of resolution work on the first user request. Be careful with address lists: if you connect to a resolved IP directly, set the correct SNI hostname so TLS still presents the right certificate.
TLS session resumption
A full TLS handshake is more expensive than a resumed one. Session resumption lets a returning client reuse negotiated state so fewer round trips are needed. TLS 1.3 already reduced handshake round trips compared with earlier versions; resumption improves the repeat case further.
If you control both ends, confirm that resumption is enabled and that certificates are served with a complete chain. A missing intermediate can force extra requests or cause validation failures on some clients.
HTTP/2 and connection reuse
HTTP/2 multiplexes many streams over one connection, which reduces the need to open multiple connections for parallel requests. HTTP/3 builds on QUIC and improves behavior when packets are lost. These protocols help most when a client makes many small requests to the same origin.
The benefit is smaller for APIs that make one request per user action and then go idle. In that case, connection keep-alive and DNS caching matter more than multiplexing.
How to investigate
Use the API checker and compare DNS lookup, connection time, TLS handshake, and TTFB across repeated runs. If connection setup is consistently large, look at network distance and proxy configuration. If TTFB dominates while setup is small, the delay is more likely in server processing.
For browser applications, confirm that the browser reuses connections. A request waterfall with repeated connection setup for every call is a strong sign that keep-alive is being lost.
Practical improvements
- Keep connections alive and size pools for concurrency.
- Avoid resolving the same hostname repeatedly inside a single request.
- Use a DNS provider with predictable latency and sane TTLs.
- Enable TLS 1.3 and session resumption.
- Check that intermediates are not terminating and reopening connections unnecessarily.
- Prefer fewer, well-shaped requests over many tiny ones when connection reuse is unreliable.
Connection setup is fixed cost. The more requests you serve on one connection, the less each request pays.
Related Tools
What is API Response Time? The Complete Guide to Measuring & Optimizing API Performance
Learn everything about API response time, why it matters for your business, and how to optimize your API performance wit...
How to Reduce API Latency: 10 Proven Strategies for 2026
Discover 10 proven strategies to reduce API latency and improve your application's performance. From caching to edge com...
API Monitoring Best Practices: The Complete Guide for 2026
Learn API monitoring best practices to ensure your services are reliable, fast, and always available. Covers uptime moni...
Understanding TTFB: Time to First Byte Explained — The Key to API Performance
A deep dive into TTFB (Time to First Byte), what it means for your API performance, and how to improve it with actionabl...
API Speed Test: How to Benchmark Your REST & GraphQL APIs in 2026
Complete guide to API speed testing. Learn how to benchmark REST and GraphQL API performance, interpret results, and opt...
How to Achieve 99.99% API Uptime: The Definitive Guide
Learn how to achieve 99.99% API uptime with proven strategies including redundancy, failover, monitoring, and incident r...