QA Interview Hub · Knowledge base · Quizzes · Українська

Networking › TCP/IP and the path of a request

What happens when you type a URL in the browser

The browser parses the URL, finds the IP via DNS, opens TCP, runs TLS for HTTPS, sends the HTTP request and renders the response. Each step has a cost and a failure point: TCP and TLS 1.3 take one RTT each, then TTFB and subresources. For «slow», locate the step: Timing in DevTools shows each phase separately, while curl -w times accumulate, so a step is the difference of neighbouring values.

Networking · TCP/IP

A page opens slowly. At which step of the path "URL → screen" is the time lost?

The product team complains that the product card loads in 2 seconds. Someone says "the server is slow", someone "the CDN", someone "the JavaScript is big". Without understanding the path of a request this is an argument of opinions. With it, it is a table: every step has a cost and its own failure points. The classic interview question "what happens when you type a URL" is exactly about this: a strong answer is not a list of words but a sequence with time costs and failure points.

How it works and why. The browser performs steps in turn, each depending on the previous one: you cannot connect without knowing the IP and cannot send a request without an encrypted channel. So the times add up, and optimisation means skipping some steps or doing them in parallel.

The path from URL to screen

1. Parse URL, HSTS, caches0 ms if the response is fresh in cache2. DNSfrom 0 to hundreds of ms: cache or chain3. TCP, then TLS1 RTT + 1 RTT (HTTP/3: 1 RTT combined)4. HTTP request, waiting (TTFB)proxy, CDN, balancer, application5. Body, subresources, renderevery new domain starts at DNS again
Figure 1. The three "hot" steps before the first request (DNS, TCP, TLS) can be skipped by reusing a connection; waiting for the response depends on the server.
  1. URL parsing and caches. Scheme, host, port (443 by default), path, query. If the host is on the HSTS list, http:// becomes https:// at once without a request to the server. If the HTTP cache holds a fresh response (by Cache-Control), there is no network at all. A Service Worker can also answer instead of the network.
  2. DNS. Browser cache, OS, resolver, authoritative server. The cost is from zero to hundreds of milliseconds. Failure points: NXDOMAIN, an unreachable resolver.
  3. TCP. One RTT to the server on port 443. Failure points: refused, timeout.
  4. TLS. One RTT in TLS 1.3: SNI, certificate check, keys, and ALPN (h2 or http/1.1). The browser learns about HTTP/3 from the Alt-Svc header or the HTTPS DNS record and tries QUIC, falling back to TCP if UDP does not pass.
  5. HTTP request. GET /path with Host, Cookie, Accept. It may pass a CDN, a balancer and a reverse proxy before reaching the application. 3xx redirects repeat part of the chain.
  6. Response. Time to first byte (TTFB) shows server processing plus the road; then the body downloads.
  7. Render. HTML parsing, subresources (CSS, JS, images, API calls). Every new domain goes through DNS, TCP and TLS again; the same domain reuses an open connection.

The cold and the warm path

First visit, cold connections

DNS, TCP and TLS from scratch for every domain. A lot of time passes before the first response byte.

Repeat visit, warm connection

DNS cached, the connection open and reused, sometimes the response is fresh in cache. Almost all the time goes to the server.

Figure 2. The difference between a first and a repeat visit is why "it is fast on my machine" guarantees nothing.

Example: breaking "slow" down by numbers. Instead of guessing, measure the cumulative time of every step:

curl -sS -o /dev/null https://shop.example.com/ -w \
"dns=%{time_namelookup} tcp=%{time_connect} tls=%{time_appconnect} \
ttfb=%{time_starttransfer} total=%{time_total}\n"
# illustration: times are cumulative, not step durations
# dns=0.021 tcp=0.065 tls=0.121 ttfb=1.480 total=1.502

The values accumulate, so each step's duration is the difference of neighbours: DNS 21 ms, TCP 44 ms, TLS 56 ms, waiting for the response about 1.36 s, body download 22 ms. The network steps together are under 130 ms, so the problem is on the server or behind it: application, database, proxy. Optimising subresources fixes nothing here. A different split (large DNS and TLS with short waiting) would point at connection infrastructure. In DevTools the Network tab shows the same steps in Timing: DNS Lookup, Initial connection, SSL, Waiting for server response, Content Download. But there each phase is shown as its own duration, not as cumulative time as in curl -w (Initial connection includes SSL). A long Queueing or Stalled often means a queue, for example the six-connections-per-domain limit of HTTP/1.1.

Limits and alternatives. The sequence is simplified: a browser often performs steps ahead of time. It may open a connection before the page needs it (preconnect) or resolve subresource names before they are requested, and preload and dns-prefetch let a developer hint this explicitly. HTTP/2 and HTTP/3 allow many requests on one connection, so "every resource is a new handshake" is true only for a new domain. A page may not render until JS has run and API responses have arrived, so a "fast server" does not yet guarantee a fast screen. For the user, metrics such as LCP matter, not TTFB alone.

Common mistakes.

  • Answering with a list of terms without numbers or failure points: the interviewer wants to see that every step costs something and can break.
  • Reading time_connect as the duration of TCP: it is cumulative, and you subtract the previous value.
  • Drawing a conclusion about speed from one run with a warm cache and an open connection.
  • Forgetting that "slow" is often not the network: a long wait (Waiting) is the server.
  • Ignoring redirects: each 3xx adds another pass through the chain.

Check yourself

curl -w shows dns=0.020 tcp=0.070 tls=0.130 ttfb=2.600. How long was the wait for the response and where do you look for the problem?

Answer

The values accumulate: the wait is ttfb minus tls, that is 2.47 s. The network steps together are about 130 ms, so the problem is on or behind the server (application, database, proxy, CDN origin), not in DNS or TLS.

Why does the same site open faster the second time and what remains if you clear the browser cache?

Answer

The second time uses the DNS cache, an open connection, the HTTP cache and cached subresources. Clearing the browser cache removes only the HTTP cache; DNS and the open connection remain, so a "cold" visit is reproduced in a new window or profile with the cache disabled.

In an interview. Junior: The browser parses the URL, finds the IP through DNS, opens a TCP connection, and for HTTPS TLS too, sends an HTTP request, gets a response and renders the page. Middle/Senior: For each step I name the cost and the failure point: HSTS and caches, DNS, TCP and TLS at one RTT each, ALPN, TTFB, subresources with connections of their own. For "slow" I use Timing in DevTools or curl -w and localise the step first, and only then optimise.

More articles in this chapter