0002 - TCP vs. UDP

Publish date: 2025-06-26
Tags: Networking, Interview-Questions

Core Comparison

Feature TCP (Transmission Control Protocol) UDP (User Datagram Protocol)
Connection Connection-Oriented: Requires a “handshake” to establish a connection before data is sent. Connectionless: Just sends packets (datagrams) without establishing a connection. Fire-and-forget.
Reliability Reliable: Guarantees that data is delivered in the order it was sent and is error-checked. It retransmits lost packets. Unreliable: No guarantee of delivery, ordering, or error checking. Packets may be lost, duplicated, or arrive out of order.
Ordering Ordered: Packets are reassembled in the correct sequence. Unordered: Datagrams are independent and may arrive in any order.
Overhead High: The TCP header is larger (20 bytes) due to sequence numbers, acknowledgments, etc. Low: The UDP header is much smaller (8 bytes).
Speed Slower: Due to the overhead of reliability checks, handshakes, and congestion control. Faster: No connection setup, no acknowledgments.
Use Cases Web Browse (HTTP/S), file transfers (FTP), email (SMTP), database connections. Anything where data integrity is paramount. Video/audio streaming, online gaming, DNS, VoIP. Anything where speed is more critical than 100% reliability.

How TCP Achieves Reliability

When to Choose UDP (and how to build reliability on top)

Tags: Networking, Interview-Questions