Networking Basics: OSI Model, TCP/IP, DNS, and HTTP
Understand how computers communicate. Learn the OSI model layers, TCP handshake, DNS resolution, HTTP versions, and what really happens when you type a URL.
What Happens When You Type a URL?
Before diving into abstract models and protocols, let's ground ourselves in something concrete. Every time you type https://google.com into your browser, a complex choreography of systems kicks into action. Understanding this end-to-end flow is the single most valuable mental model in system design.
Here's what happens, simplified:
- DNS Lookup — Your browser asks "what IP is google.com?"
- TCP Connection — Your computer establishes a connection to that IP
- TLS Handshake — The connection is encrypted (HTTPS)
- HTTP Request — Your browser asks for the webpage
- Server Response — The server sends back HTML, CSS, JavaScript
- Browser Rendering — Your browser paints the page
Each of these six steps involves different layers of the networking stack. Let's understand each one.
Why this matters: In system design interviews, "what happens when you type a URL" is the most common warm-up question. A strong answer demonstrates you understand the full stack — from DNS to rendering.
The OSI Model (7 Layers)
The OSI (Open Systems Interconnection) model is a conceptual framework that describes how data flows from a software application on one computer to a software application on another. It divides networking into 7 layers, each with a specific responsibility.
| Layer | Name | What It Does | Common Protocols |
|---|---|---|---|
| 7 | Application | User-facing services and data | HTTP, DNS, SMTP, FTP |
| 6 | Presentation | Data translation, encryption, compression | TLS/SSL, JPEG, ASCII |
| 5 | Session | Managing connections between apps | NetBIOS, RPC |
| 4 | Transport | End-to-end communication, reliability | TCP, UDP |
| 3 | Network | Routing packets across networks | IP, ICMP, BGP |
| 2 | Data Link | Frame transmission on physical media | Ethernet, WiFi (802.11) |
| 1 | Physical | Raw bits over physical medium | Copper, fiber, radio waves |
Real-world note: The OSI model is a teaching tool. In practice, the internet uses the TCP/IP model (4 layers). But the OSI model is still what interviewers expect you to know.
How the Layers Work Together
When you send an HTTP request, data flows down the layers on your machine, across the network, and up the layers on the server:
Each layer encapsulates the data from the layer above it, adding its own header. This is why understanding the layers matters — when you debug a slow API, you need to know whether the problem is at Layer 4 (TCP retransmissions), Layer 3 (routing), or Layer 7 (slow application logic).
TCP vs UDP
The Transport Layer (Layer 4) has two main protocols, and choosing between them is one of the most fundamental design decisions you'll make.
TCP (Transmission Control Protocol)
TCP is reliable, ordered, and connection-oriented. It guarantees that:
- All data arrives
- Data arrives in order
- Corrupted data is retransmitted
It achieves this through the TCP 3-way handshake:
When to use TCP: Web browsing (HTTP), email (SMTP), file transfer (FTP), database connections — anywhere data loss is unacceptable.
UDP (User Datagram Protocol)
UDP is unreliable, unordered, and connectionless. It just sends packets (datagrams) and hopes they arrive. No handshake, no acknowledgment, no retransmission.
When to use UDP: Video streaming, VoIP, DNS queries, online gaming, real-time sensor data — where speed matters more than perfect delivery.
Interview trap: "Is UDP faster than TCP?" — The better answer is: "UDP has lower latency because it skips the handshake and retransmission. But 'faster' depends on context. TCP's congestion control actually prevents network collapse, so in congested networks, TCP may deliver more usable throughput."
DNS — The Internet's Phone Book
DNS (Domain Name System) translates human-readable domain names (google.com) into machine-readable IP addresses (142.250.80.46). Without DNS, you'd need to memorize IP addresses for every website.
DNS Resolution Steps
When you type google.com, here's the lookup chain:
- Browser Cache — Does your browser already know this IP?
- OS Cache — Does your operating system's DNS cache have it?
- Router Cache — Does your home router know?
- ISP DNS Resolver — Your ISP's recursive resolver checks its cache
- Root Server — "I don't know google.com, but here's who handles
.com" - TLD Server — "I don't know google.com, but here's Google's authoritative DNS"
- Authoritative Server — "google.com → 142.250.80.46"
Key insight: DNS is hierarchical and cached at every level. This is why DNS changes take time to propagate (TTL — Time To Live). Each record has a TTL that tells resolvers how long to cache it.
DNS Record Types
| Record Type | Purpose | Example |
|---|---|---|
| A | Maps domain to IPv4 | google.com → 142.250.80.46 |
| AAAA | Maps domain to IPv6 | google.com → 2607:f8b0:4004:800::200e |
| CNAME | Alias to another domain | www.google.com → google.com |
| MX | Mail server routing | google.com → smtp.google.com |
| TXT | Arbitrary text (SPF, DKIM) | v=spf1 include:_spf.google.com ~all |
| NS | Authoritative nameservers | google.com → ns1.google.com |
DNS and System Design
In system design, DNS matters because:
- Load balancing — DNS round-robin distributes traffic across multiple IPs
- Geo-DNS — Return different IPs based on the user's location (Cloudflare, AWS Route 53)
- CDN routing — Direct users to the nearest edge server
- Failover — DNS-based failover to a backup region
HTTP/1.1 vs HTTP/2 vs HTTP/3
HTTP is the Application Layer protocol (Layer 7) that powers the web. It has evolved significantly.
HTTP/1.1 (1997)
- Text-based protocol
- One request per TCP connection (head-of-line blocking at the application layer)
- Workarounds: multiple connections (6 per domain), domain sharding, sprites, inlining
- Persistent connections (keep-alive) — reuse TCP connection for multiple requests
HTTP/2 (2015)
- Binary protocol (not text)
- Multiplexing — multiple requests/responses over a single TCP connection
- Header compression (HPACK) — reduces overhead
- Server push — server can send resources the client hasn't requested yet
- Solves HTTP/1.1's head-of-line blocking, but still blocked by TCP head-of-line blocking (if one TCP packet is lost, all streams wait)
HTTP/3 (2022)
- Uses QUIC (Quick UDP Internet Connections) instead of TCP
- Built on UDP — eliminates TCP head-of-line blocking
- 0-RTT connection establishment — faster than TCP's 3-way handshake + TLS handshake
- Connection migration — switch networks (WiFi → cellular) without reconnecting
Don't memorize every detail. Know the progression: HTTP/1.1 (sequential, text) → HTTP/2 (multiplexed, binary, TCP-based) → HTTP/3 (QUIC, UDP-based, no HOL blocking). The key insight is why each version was needed.
What to Remember for Interviews
- OSI Model — Know all 7 layers and one protocol per layer
- TCP 3-way handshake — Draw it, explain it, know why it exists (prevent stale connections, synchronize sequence numbers)
- DNS resolution chain — Browser → OS → ISP → Root → TLD → Authoritative
- HTTP evolution — HTTP/1.1 (sequential) → HTTP/2 (multiplexed over TCP) → HTTP/3 (QUIC over UDP)
- TCP vs UDP trade-offs — Reliability vs latency; know when to use each
Practice: Explain the full URL-to-page flow out loud. Time yourself. Aim for 2-3 minutes covering DNS, TCP, TLS, HTTP, and rendering at a high level.