TCP vs UDP
The Transport Layer Dilemma
When moving data across the internet at Layer 3 (IP), there is absolutely no guarantee that packets will arrive in order, or arrive at all. The Transport Layer (Layer 4) sits on top of IP to solve this, offering two wildly different protocols: TCP and UDP.
TCP (Transmission Control Protocol)
TCP is reliable, ordered, and error-checked. It acts like a certified mail courier who forces the recipient to sign for every single page of a document.
Key Features of TCP: 1. Connection-Oriented: Before data moves, TCP performs a 3-Way Handshake (SYN, SYN-ACK, ACK) to establish a connection state between the client and server. 2. Guaranteed Delivery: If a packet drops, TCP detects it and automatically retransmits the missing packet. 3. Ordered Delivery: Packets are assigned sequence numbers. The receiving OS reassembles them in the exact original order before handing them to the application. 4. Congestion Control: TCP actively monitors network congestion and throttles its transmission speed to prevent crushing the network.
Use Cases: HTTP/HTTPS, SSH, FTP, Email (SMTP). Anything where absolute data integrity is required. (If you drop a packet in a bank transfer, it's a disaster).
UDP (User Datagram Protocol)
UDP is connectionless, fast, and completely unreliable. It acts like someone standing on a roof throwing pages of a document into the wind.
Key Features of UDP: 1. Connectionless: No handshakes. It just starts blasting packets at the destination IP instantly. 2. No Guarantees: There are no acknowledgments. If a packet drops, it is gone forever. UDP doesn't care. 3. No Ordering: Packets arrive whenever they arrive. 4. Lightweight: Massive reduction in header size and CPU overhead.
Use Cases: Live Video Streaming, VoIP (Discord/Zoom), Multiplayer FPS Games, DNS. Why? If you are in a Zoom call and a packet containing 10 milliseconds of audio drops, you don't want TCP to pause the entire call, go back, and fetch that audio 500ms later. By then, the conversation has moved on. You just want the app to skip the glitch and keep playing real-time audio.
Head-of-Line Blocking
TCP's greatest strength is also its weakness. Because TCP guarantees ordered delivery, a single lost segment stalls every segment queued behind it until the lost one is retransmitted. On a lossy link, this head-of-line blocking can make a reliable stream feel far slower than an unreliable one. UDP avoids it because datagrams are independent—losing one has no effect on the others.
Reliability Is Not Free
Every TCP feature costs latency: the handshake adds a round trip before data flows, acknowledgments double the packet count, and congestion control ramps up slowly. UDP gives the application raw access to the network and lets it decide what reliability it needs. Many modern protocols implement selective reliability on top of UDP—retransmitting only what matters and ignoring the rest.
The Rise of QUIC
For decades, HTTP required TCP. But TCP's heavy handshakes and "Head-of-Line Blocking" made modern mobile web browsing slow. Google engineered QUIC (the foundation of HTTP/3) by building it directly on top of UDP. They implemented lightweight, modernized reliability logic in the application layer, resulting in massive speed gains for modern web traffic. QUIC streams are independent, so one lost packet stalls only its own stream—not the whole connection.
Choosing Between Them
Use TCP when correctness is non-negotiable and latency is tolerable: web pages, file transfers, database connections, SSH. Use UDP when timeliness matters more than completeness, or when you want to implement your own reliability model: real-time media, online games, DNS, DHCP, QUIC-based transports, and service-discovery protocols. In practice, most systems use both: gRPC over TCP, DNS lookups over UDP, and video streaming that adapts between the two.