Computer Networks•18 min read•Intermediate
TCP vs UDP
Reliable streams vs fast datagrams — and why your video call uses UDP.
TCP — reliable, ordered, slow to start
TCP guarantees that every byte you send arrives, in order, exactly once. It does this with sequence numbers, acknowledgements, retransmission, and flow control. The price: the famous THREE-WAY HANDSHAKE before any data flows (SYN, SYN-ACK, ACK), and ongoing per-packet bookkeeping.
TCP three-way handshake
Before any data flows, both sides must agree on starting sequence numbers.
Server is listening. Client wants to open a connection.
- Sequence numbers — every byte has a position; receiver reassembles in order.
- Acknowledgements — receiver confirms what it got. Missing ACKs trigger retransmission.
- Flow control — receiver advertises a 'window' so the sender doesn't overwhelm it.
- Congestion control — slow start, then ramp up; back off on packet loss. This is what keeps the Internet from collapsing.
UDP — fire and forget
UDP just sends a packet. No connection, no handshake, no retries, no ordering, no guarantees. It's faster and cheaper, and that's the right call when:
- Real-time matters more than perfection (video calls, gaming) — a late packet is worse than a missing one.
- Many tiny one-shot exchanges (DNS queries) — TCP handshake overhead would dominate.
- Broadcast/multicast (network discovery).
ℹ Note
Modern HTTP/3 and QUIC actually run over UDP, with TCP-like reliability rebuilt in user space — because tweaking TCP requires kernel updates, which take a decade.