First Byte Latency: Find the Slow Layer and Fix It
Key takeaways
- TTFB is the sum of DNS, TCP, TLS, redirects, and backend processing, and backend processing is the phase that swings wildly and dominates slow p95 numbers.
- curl's -w flag with time_starttransfer lets you attribute slow TTFB to a named layer by subtracting per-phase timings in a single command.
- Caching eliminates backend processing from TTFB but does nothing for DNS, TCP, or TLS handshake costs, which happen on every request.
- Authenticated SaaS routes and session-cookie endpoints bypass most CDN caches, so they pay full backend cost on every request.
- Alert on p95 TTFB crossing a threshold for five consecutive probes across multiple regions, not on single-probe spikes or mean latency.
First byte latency is the time between a browser sending its request and receiving the first byte of your response, and it's almost always one of six layers: DNS, TCP, TLS, redirects, backend processing, or cache misses. This guide walks each layer with a specific measurement command, so you can attribute slow TTFB to a named culprit and fix it instead of guessing.
What exactly counts as 'first byte' in a TTFB measurement?
Time to First Byte is the elapsed time between a client sending an HTTP request and receiving the first byte of the response. Google's web.dev documentation defines it this way and treats a TTFB under 800ms as a reasonable target for good user experience (web.dev TTFB). Everything before that first byte — DNS lookup, TCP handshake, TLS negotiation, redirect hops, server processing — is inside the measurement.
What curl -w measures vs what a browser measures
curl -w "%{time_starttransfer}" gives you TTFB from the moment curl starts, including DNS and TLS. A browser's navigation timing does the same but adds queueing and any service worker delays. Synthetic monitors like Pingdom or UptimeRobot measure from their probe location, so their TTFB reflects network distance as much as your backend.
Why redirect hops count toward TTFB
If example.com redirects to www.example.com, the browser waits for the first response, then issues a second request. The TTFB a user experiences includes both. We break down how each layer contributes in our TTFB monitoring guide.
Which stack layers contribute the most to first byte latency?
First byte latency is the sum of five phases: DNS lookup, TCP connect, TLS handshake, redirects, and backend processing. Connection setup phases are usually small and stable; backend processing is the one that swings wildly and causes your worst p95 numbers.
DNS and connection setup
A DNS lookup typically costs 10-50 ms when cached, and up to a few hundred ms on a cold recursive resolver. TCP connect adds roughly one round trip, so 10-70 ms for most US users. These phases are worth fixing once (low TTLs, HTTP/3, a CDN) and then mostly forgetting.
TLS handshake cost
TLS 1.3 needs one round trip; TLS 1.2 needs two. On a 50 ms round trip, that is the difference between ~50 ms and ~100 ms added to every uncached request. Full TLS handshakes only apply to new connections, so connection reuse and keep-alives matter as much as the protocol version.
Backend processing and cache misses
This is the phase that dominates slow TTFB. A cache hit at the edge might return first byte in under 100 ms total; a cache miss that triggers three database queries plus an external API call can push backend processing past 500 ms. Redirects are the sneaky one: each one adds a full DNS+TCP+TLS cycle before the real request even starts.
Typical magnitudes for a healthy uncached request:
| Phase | Typical cost |
|---|---|
| DNS lookup | 10-50 ms |
| TCP connect | 10-70 ms |
| TLS handshake | 30-100 ms |
| Redirects | 100-500+ ms each |
| Backend processing | 50 ms (fast) to 1000+ ms (cache miss, slow queries) |
If your total TTFB is over ~600 ms and connection phases look normal, the backend is your suspect. Breaking phases apart per probe location is the core of latency monitoring for uptime and response times.
How do you tell whether slow TTFB is DNS, TLS, or backend processing?
Slow first byte latency is almost never one layer failing. It is one layer being slow while four others behave, so the job is to measure each layer in isolation and compare. The decision tree below takes about five minutes and tells you which layer owns the problem.
Step 1: isolate DNS with dig
Run dig yourapp.com and read the "Query time" line. Anything under 50ms is fine; anything above 200ms means your resolver or authoritative DNS is a suspect. Run it twice: the first query may be a cache miss, the second shows steady-state.
Step 2: isolate TLS with openssl s_client
Run openssl s_client -connect yourapp.com:443 -servername yourapp.com and check the handshake output. Slow TLS usually means a missing session resumption config or a certificate chain forcing extra round trips, not a slow server.
Step 3: isolate backend with curl -w time_starttransfer
This is the step that settles most arguments. curl's -w flag exposes per-phase timing variables, including time_starttransfer, which is the moment the first byte of the response body arrives (curl documentation for the -w timing variables). The long paragraph below is the method worth copying:
curl -o /dev/null -s -w "dns:%{time_namelookup} tcp:%{time_connect} tls:%{time_appconnect} ttfb:%{time_starttransfer} total:%{time_total}\n" https://yourapp.com
Subtract to attribute: time_starttransfer minus time_appconnect is backend processing plus redirect hops. If DNS, TCP, and TLS are all under 100ms combined but TTFB sits at 900ms, your database query or cold cache is the culprit, and no CDN will save you. If time_appconnect dominates, fix TLS. If time_namelookup dominates, fix DNS. This is the same breakdown protocol-level probes report, which is why URL-only checks on tools like UptimeRobot or Pingdom-style monitors can miss a backend that degrades from 200ms to 2s while still returning a 200. For the socket-level equivalent on persistent connections, see our deep websocket monitoring subprotocols latency guide.
Step 4: confirm from a user's location with WebPageTest
Local numbers lie if your users are elsewhere. Run the same URL through WebPageTest from a region matching your customers and compare its TTFB to your curl numbers. A large gap points at network distance or CDN coverage rather than your backend.
How do you measure TTFB from the user's location rather than your data center?
A curl from your laptop or data center lies. Your cache is warm, the RTT to your own server is a few milliseconds, and same-region peering skips the congested paths your customers hit. You get a flattering number that has nothing to do with what a user in Ohio or London experiences.
External probes vs synthetic lab tests
External probes are the fix. Tools like StatusPulse run protocol-level checks from distributed locations, so you see the TTFB a real network path produces, not a same-rack one. Pingdom and UptimeRobot offer the same idea at the URL-check level; StatusPulse probes the full stack at $5/mo where Statuspage.io-style pricing would cost far more. The catch: probe locations are still a sample, not your actual user distribution.
Reading the WebPageTest waterfall for TTFB
WebPageTest lets you pick a test location and connection type, then breaks the waterfall into DNS, connect, TLS, and first byte. Whatever sits in the "first byte" bar after TLS handshake is your backend processing plus cache miss time.
For production, add RUM: real user timing data from actual browsers. Averages hide the tail, so watch percentiles instead (why p50 beats averages).
When does caching actually reduce first byte latency and when does it not?
A cache hit at the edge eliminates backend processing, database queries, and app-server time from TTFB. It does nothing for DNS resolution, TCP handshake, or the TLS handshake, which still happen on every request. If your first byte latency is 400ms and 300ms of that is connection overhead, a perfect cache gets you to roughly 100ms, not to zero.
Full-page cache vs fragment vs no cache
A full-page cache (Cloudflare, Fastly, Varnish serving the entire HTML response) delivers the biggest win: edge hit means the origin never sees the request. Fragment caching caches parts of a response while still running your app to assemble the rest, so backend time shrinks but doesn't disappear. No cache means every request pays full backend cost, which is why uncacheable endpoints dominate your slowest TTFB readings.
Why authenticated SaaS dashboards rarely benefit
Anything behind a login is typically personalized, so most CDNs bypass it by default. Your dashboard, API endpoints, and anything with a session cookie will hit your origin every time. This is why a homepage can show 80ms TTFB while an authenticated app route shows 600ms from the same stack. For dynamic API routes, protocol-level checks against the real endpoint matter more than cached-page numbers; the same logic applies to GraphQL endpoints, as covered in our GraphQL API monitoring reference.
Cache headers that actually get respected
Cache-Control: max-age with s-maxage and stale-while-revalidate is what CDNs honor for shared caches. Cache-Control: private or no-store guarantees origin hits. Setting Vary incorrectly (for example, varying on Cookie) effectively disables the cache for anyone with a session. To verify what's actually cached versus revalidated, compare x-cache: HIT versus MISS headers across repeated requests, and time DNS separately with dig to confirm how much of your TTFB caching can't touch.
What TTFB thresholds should a B2B SaaS treat as a warning sign?
For API endpoints, treat under 200ms as good, 200-500ms as watch, 500ms-1s as investigate, and anything over 1s as alert-worthy. These are working thresholds, not standards: a 600ms first byte on a report-generation endpoint is fine, on your auth endpoint it means customers are feeling every login.
Thresholds by endpoint type
Static or cached pages can sit under 100ms; if they creep past 300ms, your cache is missing. Database-backed API routes earn a 200-500ms budget. Endpoints that call third-party services (Stripe webhooks, email sends) get a 1s ceiling before you investigate. Handshake overhead alone sets a floor: DNS plus TCP plus TLS typically costs 100-300ms from distant regions, which you can verify yourself with openssl s_client -timing per the openssl s_client documentation.
Why p95 beats the mean for TTFB alerting
The mean hides your worst customers. If p50 is 180ms but p95 is 1.4s, one in twenty requests is timing out on slow paths: cold caches, a saturated worker, a slow DB query. Alert on p95 crossing your threshold for five consecutive probes, and use the mean only as a trend line. A single fast probe from one region proves nothing; percentile-based alerts from multiple regions catch the degradation your paying customers actually experience.
How does first byte latency interact with uptime monitoring and alerting?
A hard-down probe only fires when your server stops answering. A TTFB threshold catches the degradation phase first: DNS resolution creeping up, TLS handshakes slowing, or your backend grinding under load. That gap is your warning window, often minutes before customers notice anything.
Setting latency thresholds on probes
Pick thresholds from measured baselines, not best-practice lists. If your median first byte is 300ms, alert at 2-3x that sustained over several checks. A single slow probe is noise; five consecutive probes above threshold is an incident. Wire those into PagerDuty with the same escalation you'd use for a hard outage.
Avoiding false alarms from network jitter
Probe from multiple locations and require agreement before paging. One region showing 2s TTFB while four others sit at 300ms is usually transit trouble, not your stack. Page only when a majority of locations breach the threshold, and treat single-region breaches as dashboard warnings. This is where protocol-level probes earn their keep over plain URL checks: they show you which layer breached, so you can tell jitter from real degradation.
What to tell customers during a latency incident
Say it plainly: "We're seeing slow response times affecting some requests; investigating." A status page update takes 30 seconds and cuts support tickets. Silence during degradation costs more trust than the slowness itself.
FAQ
Is a high TTFB bad for SEO rankings?
Indirectly, yes. Google treats TTFB as a component of Core Web Vitals and recommends keeping it under 800ms per its web.dev documentation. Slow first byte delays every subsequent render step, hurting Largest Contentful Paint, which is a confirmed ranking signal. A 1.5s TTFB won't sink you alone, but it compounds into metrics Google does measure.
What is a good time to first byte for an API endpoint?
Under 200ms is good, 200-500ms is acceptable for database-backed routes, and 500ms-1s deserves investigation. Anything past 1s should trigger alerts. Context matters: a report-generation endpoint at 600ms is fine, while your auth endpoint at 600ms means customers feel every login. Set thresholds from your own measured baselines rather than generic lists.
Does a CDN always lower first byte latency?
No. A cache hit at the edge removes backend processing, database queries, and app-server time, which is the biggest win. But a CDN does nothing for DNS resolution, TCP handshake, or TLS negotiation, which happen on every request. If 300ms of your 400ms TTFB is connection overhead, a perfect cache only gets you to roughly 100ms.
Why is my TTFB fine locally but slow for users in other regions?
Your local test has a warm cache, a few milliseconds of RTT to your own server, and same-region peering that skips congested paths. Distant users pay full DNS plus TCP plus TLS cost, typically 100-300ms before your backend even starts. Test from a WebPageTest location matching your customers, or use distributed probes, to see the real number.
How is TTFB different from total page load time?
TTFB measures only the elapsed time from request sent to the first byte of the response arriving. Total page load includes everything after: downloading HTML, CSS, JavaScript, images, executing scripts, and rendering. A page can have a fast 100ms TTFB yet load slowly because of heavy assets, or a 900ms TTFB and load fine once the bytes start flowing.