ArcLibrary

TCP vs UDP (Comparison)

When to use TCP, when to use UDP — one table + a few rules of thumb.

TCPUDPComparison
核心 · Key Idea

In one line: TCP gives you reliability; UDP gives you simplicity + realtime. "Must arrive in order" → TCP. "Low latency, drops OK" → UDP. HTTP/3 picks UDP because it implements reliability inside QUIC.

Side-by-side#

DimensionTCPUDP
Connection3-way handshakeNone
ReliabilitySEQ + ACK + retransmitNone
OrderGuaranteedNot guaranteed
Flow controlSliding windowNone
Congestion controlReno / CUBIC / BBRNone (app-level)
Data shapeByte stream (no boundary)Datagram (boundaried)
Header20+ bytes8 bytes
Broadcast / MulticastNot supportedNative
Typical protocolsHTTP/1/2, SSH, SMTP, DB, TLSDNS, DHCP, NTP, VoIP, QUIC
NAT-friendlinessEasy (router watches SYN/FIN)Harder (relies on timeouts)

Choosing#

Rules of thumb#

  • HTTP/1/2, SSH, SMTP, IMAP, DB connections: TCP.
  • DNS, DHCP, NTP: UDP (light, single Q&A).
  • VoIP / video conferencing / live streams / games: UDP, lost frames don't matter much.
  • HTTP/3: QUIC over UDP — wants reliability and avoidance of TCP head-of-line blocking.
  • Maximum throughput (data-centre internal / high-frequency trading): UDP + custom reliability (KCP / DPDK).

Easy confusions#

TCP
Reliable + ordered + congestion-controlled.
Handshake overhead — **correctness first**.
UDP
Connectionless + no guarantees.
Zero handshake — **realtime first**.

Further reading#