Networking · Lesson 5 of 12 · 20 min

The Request Journey: DNS, TCP, TLS and HTTP

What happens between typing a URL and the first byte back: DNS, the TCP handshake, TLS, and how HTTP/1.1, 2 and 3 differ.

✓ Walk a request from URL to response and count the round trips✓ Explain how DNS caching and TTL affect failover✓ Compare HTTP/1.1, HTTP/2 and HTTP/3
Say it in 30 seconds
  • 4 round tripsCold HTTPS with TLS 1.3, DNS uncached
  • 200 msThat journey at a 50 ms round trip
  • 1 round tripA warm, kept-alive connection
Show what to say

“The browser resolves the name through DNS, opens a TCP connection, negotiates TLS, then sends the HTTP request, and each stage costs at least one round trip. On a repeat visit the address, the connection and the TLS session are reused. HTTP/2 multiplexes streams on one connection, and HTTP/3 over QUIC also removes TCP head-of-line blocking.”

Trade-offs

  • Long vs short DNS TTL: a long TTL saves lookups; a short one lets you fail over fast but adds resolver load.
  • HTTP/2 vs HTTP/3: HTTP/2 multiplexes over TCP and stalls on loss; HTTP/3 isolates streams but UDP can be blocked and costs more CPU.
  • TLS 0-RTT vs 1-RTT: early data saves a round trip for returning clients but can be replayed, so only safe requests.

Bring it up before they ask

A bad DNS record or expired certificate is fixed in minutes but caches keep serving it for the TTL, so lower TTLs before risky changes.

0 of 0 sections ticked
30-second answer

Before a server sees your request, the client resolves a name with , opens a connection and sets up , each costing at least one round trip. shares one connection between requests, and also removes TCP's .

What happens when you type a URL

Four stages in order: find the address (), connect (), secure it (), ask for the page (HTTP).

Read more · 112 words

Each needs at least one round trip, so is the round-trip time times the trips.

Press Play to watch it run · 8 steps

The browser resolves the name to an address, opens a TCP connection, sets up TLS, then sends the HTTP request. Each stage waits at least one round trip.

From typing a URL to the first response byteThe browser resolves the name to an address, opens a TCP connection, sets up TLS, then sends the HTTP request. Each stage waits at least one round trip.address of example.com?93.184.216.34, TTL 300 sDNS: 1 round trip when not cachedSYNSYN-ACKTCP handshake: 1 round tripACK + ClientHello (key share)ServerHello, certificate, FinishedTLS 1.3 handshake: 1 round tripFinished + GET /200 OK + HTML
  • Client
  • DNS
  • Service
Text description
  1. Browser → DNS resolver: address of example.com?
  2. DNS resolver replies to Browser: 93.184.216.34, TTL 300 s
  3. Browser → Server: SYN
  4. Server replies to Browser: SYN-ACK
  5. Browser → Server: ACK + ClientHello (key share)
  6. Server replies to Browser: ServerHello, certificate, Finished
  7. Browser → Server: Finished + GET /
  8. Server replies to Browser: 200 OK + HTML

DNS: names to addresses

Computers connect to addresses, not names.

Read more · 134 words

Your browser asks a recursive resolver. On a cold the resolver follows referrals: a root server points to the .com servers, which point to the domain's authoritative server, which holds the answer.

Every answer carries a , how long anyone may cache it. That is why is fast but changes are slow: lower the TTL a day before a planned move.

Press Play to watch it run · 7 steps

The browser asks its resolver. On a cold cache the resolver asks a root server, then the .com server, then the domain's own name server, and caches the answer for its TTL.

Resolving www.example.comThe browser asks its resolver. On a cold cache the resolver asks a root server, then the .com server, then the domain's own name server, and caches the answer for its TTL.BrowserResolvercaches by TTLRoot server.com serverAuthoritativeexample.com

Tap any box to see what it is and what it talks to.

  • Client
  • DNS
Open in playground
Text description
  1. Browser asks: address of www.example.com?
  2. Resolver asks a root server. It does not know, but points to the .com servers.
  3. Referral: ask the .com servers.
  4. Resolver asks a .com server, which points to example.com's name server.
  5. Resolver asks the authoritative server for the real answer.
  6. 93.184.216.34, valid for 300 seconds.
  7. Answer returned and cached in the resolver.
// A toy recursive resolver. Each server answers with either an address (and a TTL)
// or a referral: "I don't know, ask that server." Answers are cached until their TTL runs out.
export function makeResolver(servers, now = () => Date.now()) {
  const cache = new Map(); // name -> { ip, expires }
  return function resolve(name) {
    const hit = cache.get(name);
    if (hit && hit.expires > now()) return { ip: hit.ip, queries: 0 };
    let server = 'root';
    for (let queries = 1; queries <= 8; queries++) {
      const reply = servers[server](name);
      if (reply.ip) {
        cache.set(name, { ip: reply.ip, expires: now() + reply.ttl * 1000 });
        return { ip: reply.ip, queries };
      }
      server = reply.refer; // follow the referral
    }
    throw new Error('too many referrals');
  };
}

The TCP handshake

gives ordered, reliable delivery over unreliable packets.

Read more · 91 words

The client sends SYN, the server answers SYN-ACK, and the client's completes it: one round trip before data flows, and the ACK can already carry the next stage's first bytes.

Three messages are needed because each side must show it can send and receive and learn the other's starting sequence number. It also stops a delayed old SYN from opening a connection nobody wants. Lesson 6 goes inside TCP.

TLS: encryption and identity

adds confidentiality, integrity and authentication on top of .

Read more · 61 words

In TLS 1.3 the client's first message carries its half of a key exchange. The server replies with its half, its certificate and proof it holds the private key. Both derive one session key and the request follows: one round trip.

The browser trusts the certificate if it chains to a known authority, matches the hostname and has not expired.

Interactive

Handshake timeline

Every new HTTPS connection pays round trips before the first byte of the response. Keep-alive pays them once.

Protocol
0 ms50 ms100 ms150 ms200 ms250 msNew connection: 4 round trips = 200 msDNS: 1 RTT = 50 ms. Ask the resolver for the server's IP address and wait for the answer.DNS TCP: 1 RTT = 50 ms. SYN → ← SYN-ACK. The final ACK rides along with the first TLS message.TCP TLS 1.3: 1 RTT = 50 ms. One round trip: ClientHello with a key share → ← ServerHello, certificate, Finished. The client's Finished goes with the request.TLS 1.3 Request: 1 RTT = 50 ms. GET → ← response (server time not included).Request Kept-alive connection: 1 round trip = 50 msRequest: 1 RTT = 50 ms. Same connection, already encrypted: just GET → ← response.Request
  • DNS lookup
  • connection setup (TCP, TLS or QUIC)
  • the request
  • gridlines = 1 RTT
Cold request
200 ms
4 RTT
Kept-alive
50 ms
1 RTT
Saved each time
150 ms
75% of cold
10 in a row
650 ms
vs 2,000 ms all cold

TLS 1.3 at 50 ms RTT: a cold HTTPS request costs DNS 50 + TCP 50 + TLS 1.3 50 + Request 50 = 200 ms before the response starts; on a kept-alive connection it's 50 ms. A resumed session can even send the request in its first flight (0-RTT), but only for requests that are safe to replay.

What crosses the wire
  1. DNS (1 RTT, 50 ms): Ask the resolver for the server's IP address and wait for the answer.
  2. TCP (1 RTT, 50 ms): SYN → ← SYN-ACK. The final ACK rides along with the first TLS message.
  3. TLS 1.3 (1 RTT, 50 ms): One round trip: ClientHello with a key share → ← ServerHello, certificate, Finished. The client's Finished goes with the request.
  4. Request (1 RTT, 50 ms): GET → ← response (server time not included).

HTTP/1.1, HTTP/2 and HTTP/3

Read more · 186 words
HTTP/1.1HTTP/2HTTP/3
TransportTCPTCPQUIC (over UDP)
Requests per connectionOne at a timeMany streamsMany streams
Head-of-line blockingBetween requestsIn TCP, on lossPer stream only

HTTP/1.1 handles one request at a time per connection, so browsers open about six. multiplexes streams on one connection, but they share one byte stream, so one lost packet stalls all of them. runs on QUIC: a lost packet delays only its own stream, 1.3 is built into the handshake, and a connection survives a change of network.

Putting numbers on it

Assume a 50 ms round trip to the server and nothing cached.

Read more · 125 words
SetupRound tripsTime to the response
DNS + TCP + TLS 1.2 + request1 + 1 + 2 + 1 = 5250 ms
DNS + TCP + TLS 1.3 + request1 + 1 + 1 + 1 = 4200 ms
DNS + QUIC + request1 + 1 + 1 = 3150 ms
Warm connection, request only150 ms

The biggest wins are not new protocols but not repeating the setup: keep connections alive and reuse them, serve from a near the user so the round trip itself is short, and resume sessions.

Speeding up the first byte

Read more · 231 words
  • Connection reuse. and mean the handshakes are paid once.
  • Nearby servers. A or edge node ends the and handshake close to the user.
  • Resumption. A returning client can resume a TLS session and skip full key exchange. TLS 1.3 early data (0-RTT) saves another round trip but can be replayed, so use it only for safe, repeatable requests.
  • Hints. preconnect opens the connection early; dns-prefetch resolves a name early.
  • Fewer origins. Each extra hostname costs its own , TCP and TLS setup.

For how pools and keep-alive show up on the server side, see connections, pooling and keep-alive and request flows end to end.

Where this goes wrong

Read more · 249 words
  • Certificate problems. Expired, wrong hostname, or a missing intermediate certificate cause hard failures in browsers.
  • Stale DNS after . Clients that ignore TTL, or long-lived connections, keep using the dead address.
  • Middleboxes. Some networks block or throttle UDP, so must fall back to over .

Follow-up questions

What happens when you type a URL into a browser?

The browser checks , resolves the name through , opens , negotiates , sends the HTTP request and renders the response.

How does TLS give you a secure channel?

A key exchange gives both sides a secret nobody on the wire can compute, a certificate proves the server's identity, and a symmetric cipher protects the data.

What does HTTP/3 fix that HTTP/2 does not?

streams share one TCP connection, so one loss blocks all of them. delivers streams independently and merges the handshakes.

Check yourself

Question 1 of 7

Score 2 out of 3 or better to mark this page complete.

1. On a cold HTTPS connection with TCP and TLS 1.3, how many round trips pass before the browser can send the HTTP request (DNS already done)?

Next: TCP carries the whole journey. Next: how it keeps data in order, avoids overloading the network, and where it stalls.