Every HTTP request travels through the TCP/IP stack. Understanding these layers helps you debug network issues and optimize performance.
The TCP/IP Model
TCP: Reliable Delivery
The Three-Way Handshake
This adds 1.5 RTT (Round Trip Times) before any data transfer. With TLS, add another 1-2 RTTs.
Flow Control
TCP uses a sliding window to prevent the sender from overwhelming the receiver. The receiver advertises how much data it can accept.
Congestion Control
TCP starts with a small window (slow start) and increases it exponentially until packet loss occurs, then backs off. This is why new connections are slower than persistent ones.
TCP vs UDP
| Feature | TCP | UDP |
|---|---|---|
| Reliability | Guaranteed delivery | Best effort |
| Ordering | Ordered | Unordered |
| Connection | Connection-oriented | Connectionless |
| Speed | Slower (overhead) | Faster (minimal overhead) |
| Use cases | HTTP, email, file transfer | Gaming, video, DNS |
IP Addressing
What This Means for Web Performance
- Keep-Alive: Reuse TCP connections to avoid handshake overhead
- HTTP/2: Multiplexes requests over a single TCP connection
- HTTP/3 (QUIC): Uses UDP to avoid TCP head-of-line blocking
- CDNs: Reduce RTT by serving from geographically close servers
- Preconnect:
<link rel="preconnect">starts TCP+TLS handshake early