Skip to content
beginner Phase 1 · Web & Internet Foundations

How the Internet Works

Understand DNS, TCP/IP, HTTP, and the request/response lifecycle.

1h
0 problems
Topic Progress 0%

Client-Server Model

Client-Server Model

The internet is built on a simple architecture: clients request resources and servers provide them.

Key Components

Client (Browser)          Server (Web Server)
     │                          │
     │   1. HTTP Request        │
     │ ──────────────────────►  │
     │                          │  Process request
     │                          │  Query database
     │   2. HTTP Response       │  Build response
     │ ◄──────────────────────  │
     │                          │
  • Client: Your browser, mobile app, or any software that initiates requests
  • Server: A computer running software that listens for requests and sends responses
  • Network: The infrastructure (cables, routers, switches) that connects them

Types of Servers

Server Type Purpose Example
Web Server Serves HTML, CSS, JS files Nginx, Apache
Application Server Runs business logic Node.js, Django, Spring
Database Server Stores and retrieves data PostgreSQL, MongoDB
Cache Server Stores frequently accessed data Redis, Memcached

DNS: The Internet's Phone Book

When you type google.com in your browser:

  1. Browser checks its cache for the IP address
  2. If not found, asks the operating system cache
  3. OS queries the ISP's DNS resolver
  4. Resolver queries root DNS serversTLD serversauthoritative servers
  5. Returns the IP address (e.g., 142.250.80.46)
  6. Browser connects to that IP address
Browser → OS Cache → ISP DNS → Root Server → .com TLD → Google's DNS → IP Address

TCP/IP: The Transport Layer

TCP/IP is the protocol suite that makes internet communication reliable:

  • IP (Internet Protocol): Handles addressing and routing packets
  • TCP (Transmission Control Protocol): Ensures reliable, ordered delivery

The Three-Way Handshake

Client                    Server
  │─── SYN (let's talk) ───►│
  │◄── SYN-ACK (okay) ─────│
  │─── ACK (confirmed) ────►│
  │                          │
  │    Data transfer begins  │

This handshake establishes a reliable connection before any data is sent.

HTTP Request/Response Lifecycle

HTTP Request/Response Lifecycle

Every time you visit a web page, a complete request-response cycle occurs.

The Full Lifecycle

1. URL Parsing
   https://example.com:443/products?id=123
   ├── Scheme: https
   ├── Host: example.com
   ├── Port: 443
   └── Path: /products?id=123

2. DNS Resolution
   example.com → 93.184.216.34

3. TCP Connection
   SYN → SYN-ACK → ACK

4. TLS Handshake (HTTPS)
   Certificate verification → Key exchange → Encrypted connection

5. HTTP Request
   GET /products?id=123 HTTP/1.1
   Host: example.com
   Accept: text/html
   Cookie: session=abc123

6. Server Processing
   Parse request → Run business logic → Query database → Build response

7. HTTP Response
   HTTP/1.1 200 OK
   Content-Type: text/html
   Content-Length: 5432
   Set-Cookie: session=xyz789

8. Browser Rendering
   Parse HTML → Load CSS/JS → Render page

HTTP Methods

Method Purpose Idempotent Body
GET Read a resource Yes No
POST Create a resource No Yes
PUT Replace a resource Yes Yes
PATCH Partially update Yes Yes
DELETE Remove a resource Yes No

Status Code Categories

Range Category Examples
1xx Informational 100 Continue
2xx Success 200 OK, 201 Created, 204 No Content
3xx Redirection 301 Moved, 304 Not Modified
4xx Client Error 400 Bad Request, 401 Unauthorized, 404 Not Found
5xx Server Error 500 Internal Error, 503 Service Unavailable

Connection: Keep-Alive

HTTP/1.1 uses persistent connections by default. Instead of opening a new TCP connection for every request, the browser reuses the same connection:

Request 1 ──► Response 1 ──► Request 2 ──► Response 2 ──► ... ──► Connection Close

This significantly reduces latency for loading pages with many assets (images, CSS, JS).

Real-World Example: Loading a Web Page

Real-World Example: Loading a Web Page

What Happens When You Visit amazon.com

  1. DNS Resolution: amazon.com205.251.242.103
  2. TCP Handshake: Establish connection to Amazon's load balancer
  3. TLS Handshake: Negotiate encryption, verify SSL certificate
  4. HTTP Request: GET / HTTP/1.1 with cookies and headers
  5. Server Processing:
    • Load balancer routes to available server
    • Authentication middleware checks your session
    • Application renders personalized homepage
    • Queries product database, recommendation engine
  6. HTTP Response: HTML document with links to CSS, JS, images
  7. Browser Parsing:
    • Parses HTML, builds DOM tree
    • Encounters <link> and <script> tags
    • Makes additional requests for each resource
    • CSSOM + DOM = Render Tree
    • Layout → Paint → Composite

Performance Implications

  • Each request takes 20-100ms round trip
  • DNS adds 10-50ms (cached after first lookup)
  • TLS handshake adds 50-150ms (connection reuse helps)
  • HTTP/2 multiplexing allows parallel requests on one connection
  • HTTP/3 (QUIC) eliminates head-of-line blocking

Why This Matters for Full Stack Developers

Understanding the request lifecycle helps you:

  • Optimize load times: Minimize requests, use CDNs, enable compression
  • Debug issues: Use browser DevTools Network tab to trace problems
  • Design APIs: Return proper status codes and headers
  • Handle errors: Implement retry logic for failed requests
  • Improve UX: Show loading states during long requests

Quiz

1. What is the first step when a browser needs to find a website?

Question 1 options

2. What does the TCP three-way handshake accomplish?

Question 2 options

3. Which HTTP method is idempotent and used to update an entire resource?

Question 3 options

Flashcards

Question

What is DNS and why do we need it?

Answer

DNS (Domain Name System) translates human-readable domain names (google.com) into IP addresses (142.250.80.46) that computers use to communicate.

Question

What are the steps in the TCP three-way handshake?

Answer

1. Client sends SYN → 2. Server responds with SYN-ACK → 3. Client sends ACK. This establishes a reliable connection before data transfer.

Question

What is the difference between HTTP and HTTPS?

Answer

HTTP sends data in plain text. HTTPS adds TLS encryption, ensuring data confidentiality, integrity, and server authentication via SSL certificates.

Revision Notes

Key Takeaways

  • 1. The internet uses a client-server model where clients request and servers respond
  • 2. DNS translates domain names to IP addresses through a hierarchical resolution process
  • 3. TCP ensures reliable communication with a three-way handshake before data transfer
  • 4. HTTP follows a request-response cycle with methods (GET, POST, PUT, DELETE) and status codes
  • 5. Understanding the request lifecycle is essential for debugging and performance optimization

Interview Tips

  • Be able to trace the full journey of an HTTP request from URL bar to page render
  • Know the difference between TCP and UDP and when each is used
  • Explain why HTTPS matters and how TLS handshake works
  • Discuss HTTP/2 and HTTP/3 improvements over HTTP/1.1

Cheat Sheet

Internet Fundamentals

  • Client-Server: Client requests, Server responds
  • DNS: Domain → IP address resolution
  • TCP: Reliable, ordered data delivery (3-way handshake)
  • HTTP: Request-Response protocol (GET, POST, PUT, DELETE)
  • HTTPS: HTTP + TLS encryption
  • Status Codes: 2xx Success, 3xx Redirect, 4xx Client Error, 5xx Server Error