By Rahul — Google Frontend Engineer
The One-Line Answer
TCP guarantees delivery and order. UDP does not. That is the fundamental tradeoff — reliability vs speed.
TCP (Transmission Control Protocol)
- Connection-oriented: 3-way handshake before data flows
- Reliable: Every packet is acknowledged. Lost packets are retransmitted
- Ordered: Packets are reassembled in the correct order
- Flow control: Sender slows down if receiver cannot keep up
- Congestion control: Reduces speed if the network is congested
UDP (User Datagram Protocol)
- Connectionless: No handshake. Just fire and forget
- Unreliable: No guarantee packets arrive
- Unordered: Packets may arrive in any order
- No flow/congestion control: Sends as fast as possible
- Lightweight: 8-byte header vs TCP's 20-byte header
When to Use Which
TCP Use Cases
- HTTP/HTTPS (web pages, APIs)
- Email (SMTP, IMAP)
- File transfers (FTP)
- SSH
- Any time you need every byte to arrive correctly
UDP Use Cases
- DNS lookups (single request-response, fast)
- Video streaming (dropping a frame is better than pausing)
- Online gaming (old position data is useless, just send the latest)
- VoIP (slight audio glitch is better than delay)
- IoT sensor data (losing one reading out of thousands is fine)
The Frontend Connection: HTTP/3 and QUIC
HTTP/3 uses QUIC, which is built ON TOP of UDP. Why? TCP's head-of-line blocking slows down HTTP/2 when a single packet is lost. QUIC handles packet loss per-stream, so one lost packet does not block all other streams.
HTTP/1.1 → TCP (one request at a time per connection)
HTTP/2 → TCP (multiplexed, but head-of-line blocking)
HTTP/3 → QUIC over UDP (multiplexed, no head-of-line blocking)WebRTC and UDP
WebRTC (used for video calls in the browser) uses UDP for media streams. If you have ever been on a video call where the video froze momentarily but the audio kept going — that is UDP at work. It dropped the video frames rather than delaying everything.
Real-World Comparison
Summary
TCP = reliable, ordered, connection-oriented. UDP = fast, unreliable, connectionless. The web is moving toward UDP-based protocols (QUIC/HTTP/3) that build reliability on top of UDP's speed. Understanding this helps you appreciate why modern web protocols are faster.