CDN Latency Optimization: Reducing Time to First Byte
Understanding CDN Latency Components
CDN latency is the sum of several components. To optimize it, you must understand and measure each one: For foundational context, read CDN Performance Metrics: What to Measure — FlyFish NWA.
Total TTFB = DNS + TCP + TLS + Edge Processing + (Origin Fetch on miss)
Cache HIT: 5-50ms = DNS(0-20ms) + TCP(5-15ms) + TLS(5-15ms) + Edge(1-5ms)
Cache MISS: 50-500ms = above + Origin(50-500ms)
DNS Optimization
DNS resolution adds 10-50ms for cold lookups:
| Metric | Edge Processing | Origin Processing | Improvement |
|---|---|---|---|
| Latency (p50) | 8–15 ms | 120–300 ms | 15–20x faster |
| Cache Hit Ratio | 85–95% | N/A | Reduces origin load |
| TLS Handshake | 1–5 ms (nearby PoP) | 50–150 ms | 10–30x faster |
| Bandwidth Cost | $0.01–0.04/GB | $0.05–0.12/GB | 3–5x cheaper |
| Availability | 99.99% (multi-PoP) | 99.9% (single DC) | 10x fewer outages |
- Lower DNS TTL cautiously — Balance between failover speed and cache hit rate. See DNS TTL guide.
- Use DNS prefetching —
<link rel="dns-prefetch" href="https://cdn.example.com"> - Minimize DNS lookups — Serve all assets from one CDN hostname instead of multiple
Connection Optimization
TCP + TLS handshake adds 20-100ms:
- TLS 1.3 — 1-RTT handshake instead of 2-RTT for TLS 1.2. Configure minimum TLS 1.2.
- 0-RTT resumption — TLS 1.3 supports 0-RTT for repeat connections. First request after session resumption has zero handshake latency.
- HTTP/3 (QUIC) — Combined transport + crypto handshake in 1 RTT, or 0 RTT for repeat connections. See HTTP/3 guide.
- Connection coalescing — Reuse existing connections for multiple domains. See connection coalescing.
Edge Processing Optimization
Processing at the edge typically adds 1-5ms:
- Simplify WAF rules — Fewer, more targeted rules process faster. See WAF configuration.
- Optimize cache key — Simpler cache keys mean faster lookups
- Minimize edge transforms — Each transform (compression, image resize) adds processing time
Cache Hit Ratio Impact
The single biggest latency factor is whether the response is a cache hit or miss. Improving cache hit ratio from 80% to 95% means 75% fewer users experience cache-miss latency.
Origin Latency Reduction
For cache misses, origin response time dominates:
- Use an origin shield — Shield location close to origin reduces edge-to-origin RTT
- Keep-alive connections — Persistent connections between CDN and origin eliminate per-request handshake overhead
- Origin compute optimization — Faster origin responses directly reduce miss latency
- Edge caching of dynamic content — Even 1-second micro-caching eliminates most origin requests
Network Path Optimization
CDNs optimize network paths:
- Anycast routing — Anycast finds the topologically closest PoP
- Private backbone — CDN-owned backbone between PoPs avoids congested public internet paths
- Smart routing — Real-time traffic steering to avoid network congestion (Cloudflare Argo, Akamai SureRoute)
Preloading and Prefetching
Reduce perceived latency by fetching resources before they're needed:
<link rel="preconnect">— Start TCP+TLS handshake early<link rel="preload">— Fetch critical resources immediately- 103 Early Hints — CDN sends preload hints before the main response
See prefetch and preload strategies for implementation details.