Skip to the content

Lesson 245 of 296

What happens when you type a URL: DNS, TCP and TLS

What you will learn

  • The full journey of a request, step by step
  • How DNS turns a name into an IP address
  • TCP and the three-way handshake
  • TLS and HTTPS: keys, certificates and the handshake
  • What the server and browser do next
On this page

This is one of the most asked interview questions of all time. Answer it as a clear sequence, then go deeper wherever the interviewer wants.

Step 1: the browser parses the URL

https://www.jobprep.example/lessons?id=7

PartValue
Schemehttps (HTTP over TLS, default port 443)
Hostwww.jobprep.example
Path/lessons
Queryid=7

If you typed words without a scheme, the browser may treat them as a search. With HSTS (a header telling the browser "always use HTTPS for this site"), the browser upgrades http:// to https:// itself.

Step 2: DNS: finding the IP address

Computers connect to IP addresses (IPv4 like 203.0.113.10, or IPv6 like 2001:db8::1), not names. DNS (Domain Name System) is the internet's phone book.

  1. The browser checks its own cache, then the operating system's cache (and the hosts file).
  2. If not found, the OS asks a recursive resolver: usually your internet provider's, or a public one such as 1.1.1.1 or 8.8.8.8.
  3. If the resolver does not have it cached, it walks the hierarchy:
    • A root server: "who handles .example?"
    • The TLD server for .example: "who handles jobprep.example?"
    • The domain's authoritative name server (for example Route 53 or Cloudflare): "www.jobprep.example is 203.0.113.10."
  4. The answer is cached at each level for its TTL (time to live).

Common DNS record types:

RecordMaps
A / AAAAName → IPv4 / IPv6 address
CNAMEName → another name (an alias)
MXMail servers for the domain
TXTText, used for verification and email security (SPF, DKIM, DMARC)
NSThe authoritative name servers

Why DNS changes "take time": old answers stay cached until their TTL expires. Lower the TTL before planned migrations.

Step 3: TCP connection

TCP (Transmission Control Protocol) gives a reliable, ordered stream of bytes over the unreliable internet: lost packets are re-sent, out-of-order packets are reordered. It starts with the three-way handshake:

Client → Server:  SYN          "I want to connect"
Server → Client:  SYN-ACK      "OK, I acknowledge"
Client → Server:  ACK          "Connected"

This costs one round trip before any data is sent. (HTTP/3 uses QUIC over UDP instead, Lesson 246.)

Step 4: TLS handshake (the S in HTTPS)

TLS (Transport Layer Security) encrypts the connection and proves the server's identity.

  1. Client Hello: supported TLS versions and cipher suites, and the hostname (SNI, Server Name Indication, so one IP can serve many sites).
  2. Server Hello + certificate: the server picks the settings and sends its certificate: a document that says "this public key belongs to www.jobprep.example", signed by a Certificate Authority (CA) such as Let's Encrypt.
  3. The browser verifies the certificate: the CA chain leads to a root CA the operating system trusts, the name matches, it has not expired or been revoked.
  4. Key exchange: client and server use an asymmetric key exchange (Diffie-Hellman over elliptic curves) to agree a shared secret without ever sending it.
  5. Both sides derive symmetric session keys and from then on encrypt everything with fast symmetric encryption (AES-GCM or ChaCha20).

TLS 1.3 (the current version) completes this in one round trip (and can resume earlier sessions in zero round trips). TLS 1.0 and 1.1 are obsolete.

Why both kinds of encryption: asymmetric (public/private keys) solves "how do we agree a secret with a stranger?" but is slow; symmetric (one shared key) is fast for bulk data.

Step 5: the HTTP request

GET /lessons?id=7 HTTP/2
Host: www.jobprep.example
Accept: text/html
Cookie: sid=...

On the way it may pass through a CDN (Lesson 234), which can answer from cache, then a load balancer (Lesson 233), often terminating TLS, then a reverse proxy such as nginx (Lesson 248), then your application server, which may query a cache and a database, and finally returns a response (200 OK with HTML).

Step 6: the browser renders

  1. Parse HTML into the DOM; parse CSS into the CSSOM (Lesson 86).
  2. Discover more resources (CSS, JavaScript, images, fonts) and fetch them, often over the same connection.
  3. Build the render tree, calculate layout, paint, and composite.
  4. Run JavaScript, which may fetch data and change the page.
  5. Connections stay open (keep-alive) for later requests.

Short version for interviews

"The browser parses the URL, resolves the hostname through DNS caches and resolvers down to the authoritative name server, opens a TCP connection with a three-way handshake, performs a TLS 1.3 handshake that verifies the certificate and agrees symmetric keys, then sends the HTTP request, which may pass through a CDN, load balancer and reverse proxy to the application and database. The response HTML is parsed into the DOM and CSSOM, more resources are fetched, and the page is laid out, painted and made interactive by JavaScript."

Key words

WordMeaning
DNSTurns names into IP addresses
Recursive resolverThe DNS server that does the lookups for you
Authoritative name serverThe server holding a domain's real records
TTLHow long a DNS answer may be cached
TCPReliable, ordered byte streams
Three-way handshakeSYN, SYN-ACK, ACK
TLSEncryption and identity for connections
Certificate / CAProof of a server's identity / the authority that signs it
SNIThe hostname sent at the start of TLS
HSTSA header forcing browsers to use HTTPS

Now prove it

This lesson is complete when you pass the quiz and all three practice levels.