Concept · Networking & Delivery

TCP vs UDP

01

Why this matters

"TCP is reliable, UDP is fast" is the bumper sticker. True, but the interesting question is why you'd ever choose UDP. For decades the answer was niche (DNS, streaming). Now — with QUIC, WebRTC, and modern games — UDP is everywhere under a reliability layer you built yourself. Understanding the tradeoff means understanding what TCP gives you and what it costs.

02

What TCP does for you

  • Reliability. Retransmits lost packets. Orders them. No application gets truncated data.
  • Flow control. Sender slows down if receiver's buffer fills.
  • Congestion control. Sender slows down if the network shows loss — preventing collapse when everyone is heavy.
  • Connection semantics. Three-way handshake establishes a session with sequence numbers. Four-way teardown.

UDP offers none of this. It's a thin wrapper around IP: fire and forget, per-packet, no delivery guarantee, no ordering, no session.

03

When TCP's guarantees become the problem

Three scenarios where TCP hurts:

1. Real-time media. Voice or video: the packet for frame 42 got lost. TCP insists on retransmitting it before delivering frame 43. By the time frame 42 arrives, it's 300ms late and useless — better to skip it and stay current. UDP lets the application choose "skip" without argument.

2. High-frequency small messages. DNS queries, game server updates at 60 Hz. TCP handshake is 1 round-trip. UDP has zero. For short-lived exchanges, TCP setup is more expensive than the payload.

3. Head-of-line blocking across streams. HTTP/2 multiplexes many streams over one TCP connection. If one packet is lost, ALL streams stall until TCP retransmits it — even streams with no lost packets. HTTP/3 (QUIC over UDP) fixes this.

The point

"Fast vs reliable" is misleading. TCP's reliability mechanism causes latency spikes you can't control. UDP lets you build your own reliability tuned for your use case.

04

The comparison

PropertyTCPUDP
DeliveryGuaranteed (or connection errors)Best effort — may drop
OrderingIn-orderNo ordering
ConnectionStateful (3-way handshake)Stateless (no handshake)
Congestion controlBuilt-inYour responsibility
Header overhead20 bytes8 bytes
Setup RTT1 (handshake)0
Head-of-line blockingYesNo
Use forWeb, email, most APIsDNS, video, games, QUIC/HTTP3
05

Deep dive — QUIC and why HTTP/3 is on UDP

HTTP has always run on TCP. HTTP/2 (2015) multiplexed many streams over one TCP connection — great in theory, bad in practice because of head-of-line blocking. One lost packet stalled all streams.

QUIC (Google, 2012; standardized 2021) solved this by building a new transport on UDP:

  • Each HTTP stream gets its own independent reliable-delivery channel. A lost packet affects only its stream.
  • TLS 1.3 baked into the transport. 0-RTT resumption — repeat connections need no handshake.
  • Connection ID is not tied to IP. Switch WiFi → cellular mid-call without reconnecting.
  • Runs entirely in userspace, so new features ship with the browser/client rather than waiting for OS kernel updates.

Google and Cloudflare deploy QUIC for 30–40% of their traffic today. The ironic summary: the most important new network transport of the 2020s is UDP-based — not because TCP is bad, but because rebuilding its reliability in userspace was easier than fixing TCP.

Head-of-Line Blocking — HTTP/2 vs HTTP/3 SVG
HTTP/2 over TCP Stream 1 Stream 2 Stream 3 LOST All streams stall until stream 2's packet retransmits HTTP/3 over QUIC (UDP) Stream 1 Stream 2 Stream 3 X Only stream 2 blocked streams 1 and 3 keep flowing
06

Real-world protocols on each

TCP

HTTP/1, HTTP/2, SSH, SMTP, most DB protocols

Anything where you can't tolerate dropped data. Almost every API.

UDP direct

DNS, DHCP, NTP, SNMP, VoIP, most games

Low-latency, small-message, loss-tolerant.

UDP + custom reliability

QUIC, WebRTC, gaming netcode

When you want TCP's guarantees but not its policies.

HTTP/3

UDP via QUIC

30–40% of Google/Cloudflare traffic. Default in new browsers. On by default at most major CDNs.

07

Used in problems

WhatsApp uses UDP for voice/video (tolerates loss). Video conferencing uses UDP + custom jitter buffering. PUBG uses UDP for game-state sync (latency beats reliability). Live streaming uses UDP-based protocols (SRT, QUIC) for low-latency ingest.

Next up