TTFB: Understanding and Optimizing Time To First Byte

Master this key indicator of server performance and user experience

TTFB (Time To First Byte) is the time elapsed between when the browser sends an HTTP request and when it receives the first byte of the response. It's a fundamental indicator of your backend infrastructure performance, revealing the time needed to process a request and start sending data.

A high TTFB directly impacts user experience and SEO. Even if the rest of the page loads quickly, a slow server delays the entire rendering process. Google uses TTFB as a component of Largest Contentful Paint (LCP), one of the Core Web Vitals that influence ranking.

Understanding TTFB components allows you to target optimizations. MoniTao measures your endpoint TTFB continuously and alerts you when it exceeds your thresholds, allowing you to react before degradation affects your users.

TTFB Components

TTFB is not a monolithic block. It breaks down into several phases, each of which can be optimized:

  • DNS resolution: time to translate domain name to IP address. Typically 20-120ms depending on resolver and cache. Reducible with fast DNS (Cloudflare, Google DNS).
  • TCP connection: time to establish TCP connection (SYN/SYN-ACK/ACK handshake). Depends on network latency, typically 10-100ms. HTTP keep-alive reduces this for subsequent requests.
  • TLS negotiation: certificate exchange and HTTPS encryption establishment. Adds 50-200ms. TLS 1.3, OCSP stapling, and session resumption reduce this time.
  • Server processing time: the core of TTFB - time for the server to generate the response. Includes code execution, database queries, and serialization. Often the longest component.

TTFB Reference Values

Google and web experts have established TTFB thresholds to evaluate performance:

  • Excellent (< 100ms): optimal performance, usually achieved with efficient caching or static pages. Users perceive the site as instantaneous.
  • Good (100-200ms): acceptable performance for most dynamic sites. No SEO penalty or significant UX impact.
  • Acceptable (200-500ms): significant room for improvement. May start impacting Core Web Vitals. Optimization recommended.
  • Slow (> 500ms): performance issue to resolve as priority. Negative impact on UX and SEO. Backend diagnosis needed.

Factors Influencing TTFB

Many factors can increase or reduce your TTFB:

  • Geographic distance: speed of light imposes minimum latency (~1ms per 100km). A CDN brings content closer to users.
  • Server performance: CPU, RAM, and disk I/O limit requests processable per second. An undersized server will be slow under load.
  • Application code: PHP, Python, Node.js execution time depends on code quality, algorithms used, and cache utilization.
  • Database: often the main bottleneck. Unoptimized queries, missing indexes, or exhausted connections slow everything down.

Measuring and Analyzing TTFB

Here are several methods to precisely measure your site's TTFB:

# With curl - detail of each phase
curl -w "\nDNS:        %{time_namelookup}s\nConnect:    %{time_connect}s\nTLS:        %{time_appconnect}s\nTTFB:       %{time_starttransfer}s\nTotal:      %{time_total}s\n" -o /dev/null -s https://example.com

# Repeated measurement for average
for i in {1..10}; do
  curl -w "%{time_starttransfer}\n" -o /dev/null -s https://example.com
done | awk '{sum+=$1} END {print "Average TTFB: " sum/NR "s"}'

# In Chrome DevTools
# Network → click on request → Timing
# "Waiting (TTFB)" = server time

# With PHP for internal debug

curl breaks down times into phases, allowing you to identify if the problem comes from DNS, network, or server. The X-Server-Time header on server side helps measure pure processing time.

TTFB Monitoring with MoniTao

MoniTao offers several features to monitor your TTFB:

  • Continuous measurement: MoniTao measures response time (TTFB) at each check and records it in history for analysis.
  • Alert thresholds: configure alerts when TTFB exceeds a certain threshold (e.g., 500ms) to be notified of degradations.
  • Trend graphs: visualize TTFB evolution over time to detect progressive degradations or improvements after optimization.
  • Multi-location: measure TTFB from different geographic points to evaluate distance impact and CDN effectiveness.

TTFB Optimization Checklist

  • Baseline TTFB measured and documented
  • CDN configured with appropriate caching
  • TLS 1.3 enabled with session resumption
  • Application cache (Redis/Memcached) in place
  • Database queries optimized and indexed
  • TTFB monitoring configured with alerts

Frequently Asked Questions about TTFB

Does TTFB directly impact SEO?

Yes, indirectly. Google doesn't measure TTFB directly but uses LCP (Largest Contentful Paint) in its Core Web Vitals. High TTFB delays LCP, which can penalize your ranking. Google recommends LCP < 2.5 seconds.

Why does my TTFB vary from request to request?

This is normal. TTFB depends on many variable factors: server load, cache state, network congestion, database queries. Analyze trends and averages rather than isolated values.

Does a CDN always improve TTFB?

For cached static content, yes. For non-cacheable dynamic content, the CDN can even add slight latency (extra hop). Analyze whether your content can be cached at CDN level.

How exactly does MoniTao measure TTFB?

MoniTao measures time between sending the HTTP request and receiving the first response byte. This includes DNS resolution, TCP connection, TLS negotiation, and server processing time.

What's the difference between TTFB and response time?

TTFB measures time to first byte received. Total response time includes the complete body download. For a 50KB HTML page, response time will be TTFB + time to download the 50KB.

My TTFB is good but my site is slow, why?

TTFB only measures server time. Slowness may come from frontend: heavy JavaScript, unoptimized images, render-blocking CSS. Analyze the full waterfall with DevTools or WebPageTest.

Conclusion

TTFB is an essential indicator of your backend health. Low TTFB means your server responds quickly, allowing the rest of the loading chain to start early. The goal should be TTFB under 200ms for most pages.

TTFB optimization involves several levers: CDN for network latency, application cache to avoid repeated calculations, database optimization for queries. MoniTao allows you to monitor your TTFB continuously and be alerted as soon as it exceeds your goals.

Ready to Sleep Soundly?

Start free, no credit card required.