Client–server, DNS, and what happens when you type a URL

Clients (browsers, apps) send requests; servers process them and send responses. DNS turns a name like example.com into an IP address the client can connect to.

Why it matters

Computers find each other by IP address, but people remember names. Between typing a name and seeing a page there are several steps, and each can be slow or fail. Knowing them lets you explain latency, failover and where caching helps.

The idea

When you type a URL, the browser asks DNS for the server's IP address (often from a cache). Then it opens a TCP connection, does a TLS handshake for HTTPS, and sends an HTTP request. The request usually reaches a load balancer, which passes it to an application server. That server may read a cache or database, then sends the response back.

Calling a shop. You look up the number in a phone book (DNS), dial (TCP connection), check you're really talking to that shop (TLS), then ask your question (HTTP request).

A phone book rarely changes. DNS answers are cached for a set time (the TTL), so when a server's IP changes, some users keep reaching the old address for minutes or hours. That matters when you fail over to a new server.

How it works

  1. You type example.com. The browser checks its own DNS cache, then the operating system's.
  2. On a miss, it asks a resolver, often run by your internet provider. The resolver asks a root server ('who handles .com?'), then a .com server ('who handles example.com?'), then example.com's own name server, which returns the IP address, say 203.0.113.10. Every answer is cached for its TTL.
  3. The browser opens a TCP connection to that IP on port 443, with a three-step handshake (SYN, SYN-ACK, ACK).
  4. TLS handshake: the server shows a certificate proving it really is example.com, and both sides agree on encryption keys.
  5. The browser sends the request: 'GET /', with the header 'Host: example.com'. A load balancer receives it and passes it to one of many app servers.
  6. The app server reads from a cache or database, builds the page and sends it back. The browser then requests the images, CSS and scripts, often from a CDN.

Example

Big sites use DNS to send users to their nearest datacentre (geo-DNS), and to move traffic away from a datacentre that is down.

Key points

Trade-offs

Common mistakes

Not true: A change to a DNS record reaches every user straight away.
In fact: Resolvers and browsers keep the old answer until its TTL (time to live) runs out, so some users go to the old address for minutes or hours.

Not true: TCP = HTTP: two names for the same thing.
In fact: TCP is the reliable connection between two machines. HTTP is the format of the requests and responses that travel over that connection.

In the interview

The browser resolves the domain through DNS, usually from a cache, to get an IP address. It opens a TCP connection and does a TLS handshake, then sends the HTTP request. The request typically hits a load balancer, which forwards it to an app server; the server reads from a cache or database and sends back the response.

Part of Unit 1: Networking and APIs in the free System Design course.