Skip to main content

What Is TTFB? How Server Response Time Affects SEO and Rankings

In this article

Time to First Byte, or TTFB, is the time between a browser asking for a page and the first byte of the response arriving back. It covers everything that happens before the server has anything to show. That means the DNS lookup, the connection and TLS handshake, any redirects, and the server's own work of running code, querying the database and building the HTML. Google's guidance is that a TTFB of 0.8 seconds or under is good and anything over 1.8 seconds is poor.

TTFB affects rankings in two ways. It is not a Core Web Vital itself, but it is the first phase of Largest Contentful Paint. So every second the server takes is a second removed from the 2.5 second budget the page has to show its main content. And Google's crawl budget documentation says its crawler raises the rate at which it fetches pages from a site that responds quickly and lowers it for one that slows down. That matters for any site with more pages than Google visits in a day.

On a Django site a high TTFB is nearly always the backend: queries that run once per item, pages rebuilt for every visitor, a missing index, or a server with no spare capacity. Each has a specific fix, covered below.

What happens between the click and the first byte

  1. DNS lookup. The browser turns your domain name into an address. Usually cached, but a slow DNS provider adds a round trip on the first visit.
  2. Connection and TLS. The browser opens a connection to the server and negotiates encryption. TLS 1.3 does this in one round trip; older versions take two.
  3. Redirects. If the address the visitor typed redirects, the whole sequence starts again for the new address. A chain from http to https to www is two extra connections before any HTML is requested.
  4. The request. The browser sends the request for the page.
  5. Server work. The web server passes the request to the application server, which runs the Django view: database queries, template rendering, any calls to other services. This is the phase you control most.
  6. First byte back. The response starts travelling to the browser. The clock stops when the first byte lands.

Google's definition of TTFB includes all six, redirects and connection setup included, which is why a page can have a fast server and a slow TTFB. Distance matters too. Each round trip to a server on the other side of the world takes a measurable fraction of a second, and there are several before the first byte.

What counts as a good TTFB and how to measure it

Google's thresholds, from its web.dev documentation, are 0.8 seconds or under for good, 0.8 to 1.8 seconds for needs improvement, and over 1.8 seconds for poor. Lighthouse is stricter in its own audit and flags any server response over 600 milliseconds. We aim to keep the first byte from the UK to a few hundred milliseconds on the sites we build. That leaves the LCP budget for the image rather than the wait.

Three ways to measure it, each telling you something different:

  • PageSpeed Insights shows TTFB from real visitors in its field section, which is the figure Google sees. It is the one to trust.
  • Chrome DevTools shows a breakdown for the first request on the Network panel's Timing tab, separating DNS, connection, TLS and the wait for the server. That shows which step is slow from where you are sitting.
  • curl from the command line gives the same breakdown as numbers, and can be run from a server in another country to see what a distant visitor gets:
curl -o /dev/null -s -w "dns %{time_namelookup}  connect %{time_connect}  tls %{time_appconnect}  first byte %{time_starttransfer}\n" https://www.example.co.uk/

Measure logged out, because logged-in pages skip caches. Measure twice, because the first request after a quiet period often pays for an empty cache or a sleeping worker, and the second shows the steady state. Measure the pages that earn, not just the home page, since a product listing with hundreds of items behaves differently from a contact page.

How TTFB affects rankings and indexing

Through Largest Contentful Paint

Google breaks LCP into four phases, and TTFB is the first. If the server takes 1.5 seconds to send the first byte, the browser has one second left to find the hero image, download it and paint it. On a phone it will not manage that, and the page misses the 2.5 second threshold.

Cutting TTFB from 1.5 seconds to 0.3 is often the single largest LCP improvement available. It is invisible in a lab test run on a warm server, which is why our SEO and paid ads service fixes it in the code rather than around it. Our post on what LCP is and how to fix it covers the other three phases.

Through crawling

Google's documentation on crawl budget describes a crawl capacity limit that goes up when a site responds quickly and down when it slows or starts returning server errors. For a ten-page brochure site this never matters; Google will fetch all ten regardless. For a shop with thousands of product pages or a site that publishes often, a slow server means new and changed pages wait longer to be re-crawled. The Crawl Stats report in Search Console shows the average response time Google measured, and a rising line there usually precedes a fall in pages crawled per day. The technical SEO audit checklist includes this among the checks worth running quarterly.

Where the time goes on a Django site, and the fix for each

SymptomUsual causeFix
Slow on list pages, fine on simple onesN+1 queries: one query per item in a template loopselect_related and prefetch_related in the view
Slow on one page, getting worse as data growsA query with no index on the column it filters or sorts byAdd the index in the model's Meta and migrate
Slow everywhere, same for every visitorPages rebuilt from scratch on every requestPer-view or per-site caching with Redis
Slow under load, fine when quietToo few application workers, or a CPU-starved shared hostMore Gunicorn workers, or a VPS with its own cores
Slow first request, fast afterDatabase connections opened per request, cold cachesPersistent connections or a connection pool
Slow from abroad, fast from the UKDistance and round tripsA CDN in front of the site, or hosting nearer the audience
Slow before the server is even reachedRedirect chains, slow DNS, old TLSOne redirect, a fast DNS provider, TLS 1.3 and HTTP/2

Queries

The N+1 problem is the one we find most often. A template loops over fifty products and reads each one's category name, and Django runs fifty-one queries. Django Debug Toolbar on the staging site shows the count per page; the fix is to tell the queryset to fetch the related rows in the same query:

products = Product.objects.select_related("category").prefetch_related("images")

Missing indexes are the second. A filter or ordering on a column without an index makes the database read every row in the table, and the cost grows with the table. Add the index in the model's Meta class and the lookup becomes direct. For sites on PostgreSQL, the pg_stat_statements extension lists the queries costing the most time in total, which is the shortest route to the ones that need it. If you are still on MySQL, our guide to moving a Django database to PostgreSQL without downtime covers the switch.

Caching

A page that is the same for every visitor should be built once and served from memory until something changes. Django's cache framework does this at three levels. It can cache a whole page with the cache_page decorator, a fragment of a template with the cache tag, or a single expensive result with the low-level API. Redis is the usual backend and has been supported out of the box since Django 4.0.

from django.views.decorators.cache import cache_page

@cache_page(60 * 10)
def product_list(request):
    ...

Which layer to cache what in, and how to avoid caching one visitor's page for another, is the subject of our post on browser, server and CDN caching.

The server itself

Gunicorn's own documentation suggests a starting point of two workers per CPU core plus one. On shared hosting you often have no idea how many cores you really have or who else is using them. A slow TTFB that comes and goes with the time of day is the classic sign. Our comparison of shared, VPS and dedicated hosting explains when it is time to move. Keep the server in the country where most visitors are. For the rest, put a CDN in front of the site so the connection and TLS handshake happen close to them even when the HTML still comes from the UK.

Questions people ask

What is a good TTFB?

Google's documentation says 0.8 seconds or under is good and over 1.8 seconds is poor, measured from real visitors. A well-built site on decent hosting should manage a few hundred milliseconds for visitors in the same country.

Is TTFB a ranking factor?

Not directly. Google has said page speed is a ranking signal and that Core Web Vitals are part of its page experience signals. TTFB is the first phase of LCP, which is a Core Web Vital, so a slow server pulls the ranking metric down with it.

Does a CDN improve TTFB?

For images, CSS and scripts, yes, because they are served from a cache near the visitor. For the HTML page itself only if the CDN is allowed to cache it, which for pages with logins or baskets it usually is not. Even then it helps a little, because the connection and TLS handshake happen at the nearest edge rather than at your server.

Why is my TTFB high only sometimes?

Usually something else is using the server at that moment: a scheduled job, a backup, a database vacuum, a burst of crawler traffic, or a neighbour on shared hosting. If it is the first request after a quiet period, it is a cold cache or a connection being opened, and persistent connections and a warmed cache fix it.

Where to start

Run PageSpeed Insights on your two most important pages and read the TTFB figure in the field section. If it is under 0.8 seconds, move on to the image and script fixes, which will pay back more. If it is over, run the curl command above against the same pages, twice, and compare the first byte time with the connection time. A big gap between them is server work, and the table above tells you where to look. Paying for clicks to a page that takes two seconds to start loading is the most expensive kind of slow, so fix this before spending on ads.