Networking Fundamentals
OSI/TCP-IP layers, TCP vs UDP, HTTP evolution, DNS, and load balancing — the vocabulary every system design answer is built on.
1. OSI Model (7 Layers)
| # | Layer | Responsibility | Examples |
|---|---|---|---|
| 7 | Application | Interface for end-user applications | HTTP, DNS, FTP, SMTP |
| 6 | Presentation | Data translation, encryption, compression | TLS/SSL, JPEG, gzip |
| 5 | Session | Establishes/manages/terminates sessions | Sockets, RPC sessions |
| 4 | Transport | End-to-end delivery, reliability, flow control | TCP, UDP |
| 3 | Network | Routing between networks via logical addressing | IP, ICMP, routers |
| 2 | Data Link | Node-to-node delivery on the same network | Ethernet, MAC address, switches |
| 1 | Physical | Raw bit transmission over a medium | Cables, radio, Wi-Fi signals |
The practical model most engineers actually use is TCP/IP (4 layers): Application (HTTP/DNS) → Transport (TCP/UDP) → Internet (IP) → Link (Ethernet/Wi-Fi). OSI is mostly a teaching/reference model.
2. TCP vs UDP
- · Connection-oriented (handshake required)
- · Guarantees delivery, ordering, no duplication
- · Flow control + congestion control (slow start)
- · Higher overhead, higher latency
- · Connectionless — fire and forget
- · No delivery/order guarantees, no retransmission
- · Minimal overhead, very low latency
- · App must handle loss/reordering if it cares
3. HTTP Evolution
| Version | Key Change | Trade-off |
|---|---|---|
| HTTP/1.0 | New TCP connection per request. | Simple, but connection setup overhead on every request. |
| HTTP/1.1 | Persistent connections (keep-alive), pipelining. | Reuses TCP connections, but pipelining suffers from head-of-line blocking. |
| HTTP/2 | Multiplexing — many requests over 1 TCP connection, binary framing, header compression (HPACK), server push. | Fixes app-layer head-of-line blocking, but a single lost TCP packet still stalls all multiplexed streams (TCP-level HOL blocking). |
| HTTP/3 | Runs over QUIC (UDP-based) instead of TCP. Streams are independent at the transport layer. | Solves TCP head-of-line blocking entirely; faster connection setup (0-RTT). Needs UDP support through firewalls/NATs. |
Client Hello (supported ciphers) → Server Hello + certificate → Client verifies cert against CA, generates a symmetric session key encrypted with the server's public key → both switch to fast symmetric encryption for the actual data.
4. DNS Resolution
Record types: A (IPv4), AAAA (IPv6), CNAME (alias to another domain), MX (mail server), TXT (verification/SPF), NS (name server delegation).
5. Load Balancing, Proxies & CDN
| LB Algorithm | How | When it shines |
|---|---|---|
| Round Robin | Requests distributed sequentially across servers. | Servers are homogeneous and requests are roughly uniform cost. |
| Least Connections | Send to the server with fewest active connections. | Requests have variable duration (e.g. long-lived WebSocket connections). |
| IP Hash | Hash client IP to consistently route to the same server. | Session affinity needed without a shared session store. |
| Weighted Round Robin | Servers get traffic proportional to assigned weight. | Heterogeneous server capacity (some bigger instances than others). |
Forward proxy sits in front of clients, hiding client identity from servers (e.g. corporate proxy, VPN). Reverse proxy sits in front of servers, hiding server identity/topology from clients (e.g. Nginx, load balancer, API gateway) — also handles TLS termination, caching, compression.
Geographically distributed edge servers cache static (and sometimes dynamic) content closer to users. Reduces latency (avoids cross-region round trips) and offloads origin servers. Cache invalidation is the classic hard problem (TTL-based or explicit purge).
6. Common Interview Questions
A: Multiple TCP connections each need their own slow-start ramp-up and consume separate OS resources; multiplexing multiple logical streams over one connection avoids that overhead and lets the browser make many concurrent requests without the old '6 connections per domain' hack.
A: In TCP, if one packet is lost, all data behind it (even for unrelated streams) must wait for retransmission before the OS delivers anything to the application — because TCP guarantees strict in-order bytes on a single connection. QUIC runs over UDP and manages its own independent streams, so a lost packet only blocks its own stream, not others.
A: DNS resolution → TCP handshake (+ TLS handshake if HTTPS) → HTTP request sent → server processes and responds → browser parses HTML, discovers additional resources (CSS/JS/images), fetches them (often in parallel over HTTP/2) → renders the page.
A: TCP, because it guarantees in-order, reliable delivery on a single connection. If using UDP for latency reasons (e.g. video), the application layer must add its own sequence numbers and reordering/dedup logic.
A: In practice DNS scales via caching (TTL) and anycast — the 13 root server 'names' are actually served by hundreds of physical anycast nodes worldwide, so a client's request is routed to the nearest instance rather than a single physical machine.