TTFB: Measure It Layer by Layer and Fix It
Key takeaways
- TTFB bundles DNS lookup, TCP connect, TLS handshake, and server processing, so a spike can come from any layer and must be decomposed before you fix it.
- curl's timing variables and the Resource Timing API split TTFB into per-phase numbers, letting you tell a 380ms connection overhead problem from a 520ms slow backend.
- A CDN only lowers TTFB on cache hits; dynamic routes with no-store headers pay an extra edge-to-origin round trip and can be slower than no CDN at all.
- Keep-alive, TLS session resumption, connection pooling, and Cache-Control headers cut TTFB by tens to hundreds of milliseconds without a rewrite.
- Monitor TTFB with scheduled multi-region probes against per-endpoint baselines, because latency drift is a leading indicator of incidents that uptime checks miss.
TTFB is the time between a client's request and your server's first response byte, and it covers everything from DNS lookup to TLS handshake to your app's own processing. Breaking it into those layers tells you whether a spike means a CDN problem, a TLS issue, or slow backend code, which is exactly what you need to know before you page on-call.
What exactly counts as 'first byte' in a TTFB measurement?
TTFB is the time between the start of a request and the moment the first byte of the response arrives. Google's web.dev documentation defines it as the time between the initial request and receipt of the first byte of the response, and recommends a TTFB under 800ms (what is TTFB). The catch is "start of request": different tools pick different starting points, so the same request can produce three different numbers.
Redirects and where the clock starts
If your app redirects, the browser reports TTFB for the redirect response first. Some tools include redirect time in the total; others start the clock only at the final request. A 301 chain can add hundreds of milliseconds that one tool shows and another hides.
Why curl, browser DevTools, and monitoring probes disagree
curl's time_starttransfer starts at connection setup, excluding DNS unless you ask for it. DevTools measures from navigation start, including redirects. A monitoring probe typically measures from its own connection start to first byte, which is the number you want for alerting. Pick one definition, document it, and compare tools on that basis rather than chasing identical numbers across sources.
How do you break down TTFB into DNS, TLS, and server time?
A single TTFB number hides where the time actually goes. Split it into DNS lookup, TCP connect, TLS handshake, and server processing, and you know whether the fix is a DNS provider, a closer region, or application code.
Reading curl timing fields
curl -w gives you per-phase timings in one request:
curl -o /dev/null -s -w 'dns=%{time_namelookup} tcp=%{time_connect} tls=%{time_appconnect} ttfb=%{time_starttransfer}\n' https://api.example.com/health
time_namelookup is DNS. time_connect minus time_namelookup is the TCP handshake. time_appconnect minus time_connect is TLS. Server processing is time_starttransfer minus time_appconnect. Run it three or four times and ignore the first run, which often pays cold DNS and TLS costs.
Resource Timing API phases
In the browser, performance.getEntriesByType('resource') exposes the same split: domainLookupEnd - domainLookupStart for DNS, connectEnd - connectStart for TCP, and requestStart as the boundary where the request leaves the client. Note that requestStart to responseStart bundles network travel and server processing together, so it overstates server time on high-latency connections.
A worked example: 900ms TTFB decomposed
| Phase | Time | Cumulative |
|---|---|---|
| DNS | 120ms | 120ms |
| TCP connect | 80ms | 200ms |
| TLS handshake | 180ms | 380ms |
| Server processing | 520ms | 900ms |
Here the server is the problem, not the network: 520ms of processing against 380ms of connection overhead. If the split were reversed, you would look at region placement or TLS resumption instead. This is the same decomposition a protocol-level probe runs continuously, so a TTFB spike in your monitoring tells you which phase regressed.
What TTFB is considered good for a SaaS API or web app?
A reasonable target for TTFB on a static edge response is under 200 ms. A dynamic API endpoint that hits no database should stay under 300 ms. A DB-backed page or endpoint doing real work is doing well at 400-500 ms, and anything consistently over 800 ms will feel slow to customers regardless of what your uptime monitor says. These are working thresholds, not standards; Google's guidance for LCP treats server response times under ~200-600 ms as a reasonable budget for the TTFB portion (Optimize TTFB).
Thresholds by endpoint type
Split your endpoints before you set numbers. Health checks and CDN-served assets should sit near the 200 ms mark. Your core API routes belong in the 300-500 ms band. Login flows and report generation can legitimately run higher; judge them by their own baseline, not a global average. You can read the individual timing phases (DNS, connection, TLS, waiting) from the browser's Resource Timing API to see which phase is eating the budget.
Setting alert thresholds that avoid false alarms
Alert on sustained breaches, not single probes: three consecutive probes over threshold is a sane default. Set p95 thresholds per endpoint type rather than a global mean, and warn at 1.5x your baseline before you page anyone. That cuts false alarms while still catching the slow degradation a simple up/down check misses.
How does a CDN change your TTFB — and when does it not help?
A CDN changes TTFB by shortening the physical distance your first byte travels, but only when it can serve the response from cache.
Cache hit vs cache miss math
On a cache hit, the edge node returns the cached response in roughly the time of one round trip from the user to the edge, often 10-40ms regionally. On a cache miss, the edge must fetch the full response from your origin, then send it back. That means the user waits for two sequential round trips instead of one, so a miss can be slower than no CDN at all if your origin is well-placed relative to your users.
When a CDN makes TTFB worse
Dynamic API routes that send Cache-Control: no-store bypass the cache entirely. Every request pays the edge-to-origin detour, plus TLS handshakes on the origin connection unless you use persistent connections. POST requests and authenticated responses typically fall into this bucket.
The practical fix: cache what is genuinely cacheable (docs, marketing pages, public endpoints) with long TTLs, and route API traffic through the nearest region to your origin rather than assuming the CDN helps. Monitor TTFB per route, because your cached pages and dynamic endpoints will tell two different stories.
How do you monitor TTFB continuously, not just in one-off tests?
A Lighthouse run or a curl in your terminal tells you what TTFB was at one moment from one location. Continuous monitoring means probes that measure TTFB on a schedule from multiple regions, so you can tell the difference between "our server got slow" and "one backbone route in Frankfurt degraded." One-off tests also miss baseline drift: your TTFB creeps from 180ms to 400ms over six weeks, nobody notices, and now you're alerting on a degraded normal. For a deeper walkthrough of setting this up, see Time to First Byte (TTFB) Monitoring: A Practical Guide - StatusPulse.
Multi-region probes and baseline drift
Run probes from at least three regions: one near your origin, one near your CDN edge, one far from both. Compare each region against its own trailing baseline rather than a fixed threshold, because a 600ms TTFB from Sydney may be normal while the same number from Virginia is an incident. The measurement itself is simple to replicate: curl's -w timing variables (time_namelookup, time_connect, time_appconnect, time_starttransfer) let you break TTFB into DNS, TCP, TLS, and server wait, which is exactly what your probes should record so an alert tells you which layer moved.
Alerting on TTFB without drowning in false alarms
Alert on percentiles, not single checks. Require, say, 3 of the last 5 probes from at least 2 regions to breach before paging anyone; a single bad probe location is a network blip, not an outage. Silence alerts during deploys, and route warnings to Slack but only sustained breaches to PagerDuty. StatusPulse applies this same rule to its own probes: protocol-level checks with multi-region confirmation, because false alarms at 3 AM train you to ignore the real ones.
Which server-side fixes reduce TTFB without a rewrite?
Start with the network phases, because they are the cheapest to fix. The W3C Resource Timing spec splits TTFB into redirect, DNS, TCP, and TLS time before the server even starts responding (Resource Timing). If your DNS or TLS phases are large, no application change will help.
Cheap wins: keep-alive and TLS reuse
Enable HTTP keep-alive on your load balancer and origin so connections are reused instead of re-handshaked. Turn on TLS session resumption (session tickets or session IDs) so repeat visitors skip the full handshake. Both are config changes, not code changes, and they shave tens to hundreds of milliseconds per request.
App-layer wins: pooling and response caching
Database connection pooling is next. If each request opens a fresh Postgres or MySQL connection, you are paying 20-50ms of TCP and auth overhead every time. Use PgBouncer, your framework's built-in pool, or your platform's pooled connection strings, and cap pool size to what your database can actually serve.
Then set caching headers on responses that do not need to be dynamic. A Cache-Control header on public pages, or a short TTL on semi-static API responses, lets your CDN or reverse proxy absorb requests before they hit your app.
Finally, tune upstream timeouts. If your proxy waits 60 seconds for a hung worker, a slow dependency inflates TTFB for everyone queued behind it. Fail fast, return a partial response, and let your monitoring tell you which dependency is the bottleneck.
How does TTFB relate to uptime and incident detection?
TTFB degradation as a leading indicator
Hard downtime is obvious: the connection fails, your probe fires an alert, PagerDuty gets a page. TTFB drift is quieter. A probe that only checks "did we get a 200?" stays green while server time climbs from 180ms to 2.5s, and your customers notice before your monitoring does.
Treat latency thresholds as a second alert tier. Set a warning when TTFB crosses, say, 800ms for three consecutive probes, and a critical alert at a level that would break your SLA commitments. That catches the slow-leak failures, connection pool exhaustion, a database query regressing after a deploy, before they become outages.
The trade-off: aggressive thresholds mean false alarms. Tune them against your own baseline, not a generic benchmark.
Communicating degradation on your status page
When TTFB degrades but the service still responds, "all systems operational" is a lie your customers can verify themselves. Post a degraded-performance incident with what you know and what you're investigating.
That's the workflow StatusPulse is built around: protocol-level probes with latency thresholds feeding the same status page your customers watch, from $5/mo. It's also where it falls short today: it won't trace which layer (DNS, TLS, app) caused the slowdown the way a full APM tool would, so you'll still diagnose that yourself.
FAQ
Is a high TTFB always a server problem?
No. TTFB bundles DNS lookup, TCP connect, TLS handshake, and server processing, so a spike can come from any layer. A 900ms TTFB might be 520ms of app code or 380ms of connection overhead plus slow DNS. Decompose the phases with curl's timing variables or the Resource Timing API before blaming your backend.
What is the difference between TTFB and latency?
Latency usually refers to a single network round trip, like a ping. TTFB includes that travel time plus DNS, connection setup, TLS, and your server's processing before the first byte arrives. A server with fast network latency can still show a high TTFB because slow application code dominates, which is why decomposing TTFB into phases matters.
Does HTTP/2 or HTTP/3 affect TTFB?
Yes, mostly through connection setup. HTTP/3 uses QUIC, which combines transport and TLS handshakes, cutting round trips on new connections, which helps repeat visitors and mobile networks most. But if your TTFB is dominated by server processing, protocol upgrades will not move the number. Fix the app layer first, then measure again.
How often should I check TTFB in production?
Continuously, via scheduled probes rather than one-off tests. Run probes from at least three regions and compare each against its own trailing baseline, since a 600ms TTFB from Sydney may be normal while the same number from Virginia is an incident. One-off curl checks miss baseline drift, where TTFB creeps upward over weeks unnoticed.