Skip to content

Troubleshooting guide

How to reduce TTFB (server response time)

Time to first byte is the foundation of every page load. These fixes are ordered by how much they usually help, starting with the ones that remove work entirely.

3 min read10 sectionsUpdated

On this page

Key points

  • Cache HTML at the edge for pages that are the same for everyone.
  • Remove redirect hops before the real page.
  • Profile the server with traces to find the query or call that dominates.
  • Move servers or caches closer to users in far regions.

Measure first

Split TTFB into its parts and see which one dominates. Use real-user data for the field picture by country, and a trace for the server part:

bash
for i in 1 2 3; do
  curl -o /dev/null -s -w 'dns=%{time_namelookup} tcp=%{time_connect} tls=%{time_appconnect} ttfb=%{time_starttransfer}\n' https://example.com/
done

Fixes in order of impact

FixHelps whenTypical gain
Cache full HTML at a CDNPages are the same for all visitorsServer time drops to near zero for cache hits
Remove redirectsLinks go via http:// or a non-canonical hostOne round trip per removed hop
Fix slow queries and N+1 patternsTraces show long database spansOften hundreds of milliseconds
Cache expensive fragmentsSome data is slow but changes rarelyLarge, on every request
Serve from closer regionsVisitors are far from the originRound-trip time per hop
Avoid cold startsServerless or scale-to-zeroRemoves occasional multi-second waits
HTTP/2 or HTTP/3, TLS 1.3Older stacksFewer round trips for connection setup

Caching HTML safely

Personalized pages cannot be shared, but most of a marketing site, documentation or blog can. Common patterns:

  • Cache-Control with s-maxage for the CDN and a short max-age for browsers.
  • stale-while-revalidate so visitors get a cached page while a fresh one is fetched in the background.
  • Vary or bypass rules for signed-in users and carts.
  • Purge on publish, so content edits appear immediately.
plaintext
Cache-Control: public, max-age=60, s-maxage=600, stale-while-revalidate=86400

Making the server part faster

Open a trace for a slow request. Typical findings: one query that needs an index, the same query run once per item (N+1), a call to an external API on every page view, or template rendering that loads far more data than it shows. Fix the biggest span first and re-measure. See how to find slow database queries and our guide to caching for content sites.

Keep it from creeping back

Track TTFB at the 75th percentile per page from real users, and server latency per route in APM. VitalRix real user monitoring and APM show both, so a regression after a release is visible the same day.

Frequently asked questions

What is a good TTFB?

0.8 seconds or less at the 75th percentile of real page views is considered good. Cached pages served from a nearby CDN are often well under 200 ms.

Does a CDN always reduce TTFB?

Only for content it can serve from cache. For uncached, dynamic pages the CDN adds a hop, though connection reuse to your origin often still helps a little.

Check it now, free

Watch your own site and services with VitalRix

Uptime checks, APM, logs, real-user monitoring, alerts and status pages in one place. Every product has a free tier and no credit card is needed.