On this page
01Why interviewers ask this
Interviewers ask "what happens when you type a web address and press Enter?" They want the steps between the phone and your code.
A weak answer says "the request goes to the server". A strong answer lists the steps and the time each takes.
02The idea in plain words
Think about ordering from a shop. You look up its phone number, call and wait, and ask for what you want. The shop answers.
A web request has the same steps. A URL is a web address, such as https://results.example.in/results/4821. It has a host name (results.example.in) and a path (/results/4821).
- DNS lookup. An IP address is a number that names one computer on the network. The Domain Name System (DNS) turns a host name into an IP address. The browser asks a DNS server, a computer that keeps the list of names and IP addresses. The browser remembers the answer for a short time.
- TCP connection. TCP is a way to send data in which two computers first set up a connection. Setup takes one round trip: a message goes to the other side and the answer comes back. The receiver confirms each piece, and the sender sends again any lost piece, so data arrives complete and in order.
- HTTP request. HTTP is the set of rules for a web request and its answer. A request has a method (GET means "give me this"), a path, headers (small notes) and sometimes a body (data). Request and response take one round trip, plus the server's work time.
- HTTP response. It has a status code, a number that says what happened: 200 means OK, 404 means not found. It also has headers and a body (the page).
# The request
GET /results/4821 HTTP/1.1
Host: results.example.in
# The response
HTTP/1.1 200 OK
Content-Type: text/html
(the page)HTTPS is HTTP with a lock (encryption), so only the two ends can read the messages. The lock adds one or two round trips.
UDP is the other way to send data. It has no setup, no confirmation and no resending, so a lost piece stays lost, but it starts faster. Use it when a late piece is useless, such as in a live voice call. Use TCP when every piece must arrive, as for a web page.
A redirect is a response that says "go to another address". Its status code starts with 3, and a Location header holds the new URL. The browser sends a new request.
- 301 means moved permanently. The browser may remember it and go straight to the new address next time.
- 302 means moved for now. By default, the browser asks the old address again each time.
HTTP is stateless: the server treats each request as new. A cookie is a small piece of text that the server asks the browser to keep. After you log in, the response says Set-Cookie: sid=a81f. The browser sends Cookie: sid=a81f with each following request to that site. The server looks up the ID a81f in its own records and knows who you are. Keep only an ID in a cookie, never a password.
Stuck on something? The AI tutor has read this lesson. Ask it with a free account
03Pause and predict
Pause. Guess first.
A phone opens a page for the first time. DNS takes 30 ms, one round trip takes 50 ms, and the server needs 20 ms to work. Ignore the lock. How long until the full answer arrives?
Write your guess before you read on. The answer is in the worked example.
04Worked example
Assumptions: round trip 50 ms, DNS lookup 30 ms, server work 20 ms per request. After the first visit, the name is remembered and the connection stays open.
- First visit: DNS 30 + TCP connection 50 + request and response 50 + server work 20 = 150 ms. This answers the predict box.
- The next request on the open connection: 50 + 20 = 70 ms.
Now the address redirects to another path on the same host. That is one more request: 150 + 70 = 220 ms.
- Next visit with 301: the browser goes straight to the final page. 70 ms.
- Next visit with 302: the browser asks the old address first. 70 + 70 = 140 ms.
05Trade-offs
- TCP solves lost data. It costs a round trip to set up. I would use UDP when a late piece is worse than a missing one.
- 301 solves repeat requests. It costs the chance to change, because browsers keep the old target. I would use 302 when I may change the target.
- Cookies solve remembering a user. They cost bytes on each request. I would keep bigger data on the server.
06Common misconceptions
"TCP is always better, because it never loses data." A resend takes time, and a late word in a live call is useless.
"301 and 302 are the same." A browser may remember a 301, so a change of target may not reach some users.
07How to say it in the interview
Say it like this
The browser looks up the address with DNS, opens a TCP connection, then sends an HTTP request and reads the response. Each step takes time, so I add them up before my own code runs.
08Check your understanding
- Name the steps from typing an address to seeing the page. What does DNS return?
- One round trip is 80 ms, DNS is 40 ms and server work is 30 ms. How long does (a) the first request take, and (b) the next request on the open connection?
- A short-link site sends every click to a long address with a 301 redirect, and wants to count clicks. What goes wrong, and what do you use?
09Answers
Show the answers
- DNS lookup, TCP connection, HTTP request, HTTP response. DNS returns an IP address.
- (a) 40 + 80 + 80 + 30 = 230 ms. (b) 80 + 30 = 110 ms.
- Browsers remember a 301, so repeat clicks from one browser may never reach the site. The count is too low. Use 302.
10Sources
- Redirects: RFC 9110, sections 15.4.2 and 15.4.3, https://www.rfc-editor.org/rfc/rfc9110.html (opens in a new tab) (checked 19 Oct 2026). Cookies: RFC 6265, https://www.rfc-editor.org/rfc/rfc6265.html (opens in a new tab). The lock: RFC 8446, https://www.rfc-editor.org/rfc/rfc8446.html (opens in a new tab).
- HTTP/3 uses UDP; this lesson describes HTTP over TCP.
Try it now, no sign-up
Related lessons and practice
Ask the AI tutor about this lesson
The tutor has read this lesson. Ask in your own words, any time. Free account, 20 questions a day.
Reading never needs an account. The account is for the tutor, the quiz, your notes and your progress.