Ravindra BagaleCourses & study guides मराठी Track your progress

Chapter 2: The OSI Model and TCP/IP Model

2.4 Walk-through: what happens when you open a website?

This is my favourite interview question, so pay attention. Suppose you type https://www.example.com in your browser and press Enter. What happens in the next few milliseconds? Come on, let's go through it step by step together.

 You ──► Browser ──► DNS lookup ──► TCP handshake ──► TLS handshake ──► HTTP GET
                                                                             │
 Page shown ◄── Browser renders ◄── HTTP 200 + HTML/CSS/JS ◄── Web server ◄──┘
  1. URL parsing (L7): The browser finds the scheme (https → port 443), host (www.example.com) and path (/).
  2. DNS resolution (L7, over UDP 53): The browser checks its cache, then the OS cache and /etc/hosts, then asks the configured DNS resolver (your ISP, 8.8.8.8, or on EC2 the VPC resolver at 169.254.169.253). The resolver queries root → .com TLD → authoritative name server and returns the IP, e.g. 93.184.215.14.
  3. ARP (L2/L3): Your laptop needs the MAC address of the default gateway (Wi-Fi router) to send the first frame; ARP finds it.
  4. TCP 3-way handshake (L4): Your laptop picks an ephemeral port (e.g. 51544) and sends SYN to 93.184.215.14:443; the server replies SYN-ACK; laptop sends ACK. Connection established.
  5. Routing (L3): Packets travel through your router (NAT changes your private IP to the public IP), your ISP and many internet routers, each forwarding by destination IP.
  6. TLS handshake (L6): Browser and server agree on encryption keys; the server presents its certificate, which the browser verifies.
  7. HTTP request (L7): Browser sends GET / HTTP/1.1 with headers Host: www.example.com, cookies, etc.
  8. Server processing: On AWS this could be: Security group allows 443 → Nginx receives request → serves a static file or proxies to an app (Node/Flask/PHP) → app queries the database → response generated.
  9. HTTP response (L7): HTTP/1.1 200 OK plus HTML. The browser then requests CSS, JS and images (often over the same connection).
  10. Rendering: Browser builds the DOM, applies CSS, runs JavaScript and shows the page.
  11. Connection close / keep-alive: Connection reused for more requests, then closed with FIN/ACK.

Now open your terminal and try this with me – you can see many of these steps yourself:

# Step 2: DNS lookup
dig +short www.example.com
nslookup www.example.com

# Step 5: path taken by packets (install traceroute if missing)
traceroute www.example.com

# Steps 4, 6, 7, 9 in detail (verbose curl)
curl -v https://www.example.com -o /dev/null

Troubleshooting using layers

Website not opening from your laptop? Work bottom-up: Is the instance running (L1)? Does it have a public IP and route to an IGW (L3)? Does the security group allow port 80/443 (L4)? Is Nginx listening (ss -tlnp)? Does DNS point to the right IP (L7)? Does the app return errors (L7)?

When Mauli Dairy calls to say "the site won't open", use the order from the note above: instance running → public IP and route → security group 80/443 → Nginx listening (ss -tlnp) → DNS → app errors. One command for each step, no guessing.

Ravindra Bagale's Tip

When a website won't open, talk through the troubleshooting layer by layer, out loud, like a checklist: instance running? → route and public IP? → security group port? → is the service listening? → DNS correct? → app errors? Interviewers like this structured approach far more than random guesses.

Ravindra Bagale's Tip

Many students assume the server is down when ping fails. A security group blocks ICMP by default – so first test with curl -I http://<PUBLIC_IP> or on that port. No ping does not mean the server is off.

Lab

Chala, dig +short www.example.com, traceroute www.example.com aani curl -v https://www.example.com -o /dev/null chalva. Output madhe varchya 11 steps paiki kontya steps disat aahet te mark kara – resolved IP (step 2), TCP connect (step 4), TLS handshake (step 6) aani 200 status (step 9).