TTFB measures the time from when the browser sends an HTTP request to when it receives the first byte of the response. Google's Core Web Vitals recommend TTFB under 800ms.
What TTFB includes:
- DNS resolution time.
- TCP connection time (3-way handshake).
- TLS negotiation time (if HTTPS).
- Server processing time (DB queries, SSR render, API calls).
- Time for the first byte to travel from server to client (network latency).
Improvement strategies:
- CDN — serve responses from edge nodes close to the user; eliminates most of the geographic latency.
- Edge computing — run SSR at edge (Vercel Edge Functions, Cloudflare Workers) to reduce round-trip to origin.
- Server-side caching — cache rendered HTML or API responses in Redis; skip DB queries on cache hit.
- HTTP/2 or HTTP/3 — fewer round trips, better connection reuse.
- Optimize slow queries — profile DB and N+1 query problems; they directly inflate server processing time.
- Persistent connections —
Connection: keep-alive avoids TCP handshake on repeated requests.