Foundations

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.

15 min readnetworkingOSI modelTCP/IPDNSHTTPfoundations

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:

  1. DNS Lookup — Your browser asks "what IP is google.com?"
  2. TCP Connection — Your computer establishes a connection to that IP
  3. TLS Handshake — The connection is encrypted (HTTPS)
  4. HTTP Request — Your browser asks for the webpage
  5. Server Response — The server sends back HTML, CSS, JavaScript
  6. 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.

LayerNameWhat It DoesCommon Protocols
7ApplicationUser-facing services and dataHTTP, DNS, SMTP, FTP
6PresentationData translation, encryption, compressionTLS/SSL, JPEG, ASCII
5SessionManaging connections between appsNetBIOS, RPC
4TransportEnd-to-end communication, reliabilityTCP, UDP
3NetworkRouting packets across networksIP, ICMP, BGP
2Data LinkFrame transmission on physical mediaEthernet, WiFi (802.11)
1PhysicalRaw bits over physical mediumCopper, 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:

  1. Browser Cache — Does your browser already know this IP?
  2. OS Cache — Does your operating system's DNS cache have it?
  3. Router Cache — Does your home router know?
  4. ISP DNS Resolver — Your ISP's recursive resolver checks its cache
  5. Root Server — "I don't know google.com, but here's who handles .com"
  6. TLD Server — "I don't know google.com, but here's Google's authoritative DNS"
  7. 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 TypePurposeExample
AMaps domain to IPv4google.com → 142.250.80.46
AAAAMaps domain to IPv6google.com → 2607:f8b0:4004:800::200e
CNAMEAlias to another domainwww.google.com → google.com
MXMail server routinggoogle.com → smtp.google.com
TXTArbitrary text (SPF, DKIM)v=spf1 include:_spf.google.com ~all
NSAuthoritative nameserversgoogle.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

  1. OSI Model — Know all 7 layers and one protocol per layer
  2. TCP 3-way handshake — Draw it, explain it, know why it exists (prevent stale connections, synchronize sequence numbers)
  3. DNS resolution chain — Browser → OS → ISP → Root → TLD → Authoritative
  4. HTTP evolution — HTTP/1.1 (sequential) → HTTP/2 (multiplexed over TCP) → HTTP/3 (QUIC over UDP)
  5. 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.