SDI.
All Concepts
Networkingtransport-layerreliabilitycongestion-controlstreamingreal-timeQUICthree-way-handshake

TCP vs UDP

TCP (Transmission Control Protocol) provides reliable, ordered, connection-oriented byte-stream delivery with congestion control, while UDP (User Datagram Protocol) provides fast, connectionless, best-effort datagram delivery without guarantees.

TCP establishes a connection via a three-way handshake (SYN, SYN-ACK, ACK), then guarantees that data arrives in order, without loss or duplication, using sequence numbers, acknowledgments, retransmissions, and flow/congestion control. It's used for HTTP, SSH, email, databases — anything where correctness matters. UDP skips the handshake and sends datagrams with no guarantees — packets can be lost, duplicated, or arrive out of order. It's used for DNS, video streaming, gaming, and VoIP — anything where speed matters more than reliability. QUIC (used by HTTP/3) builds reliability on top of UDP to avoid TCP's head-of-line blocking.

Tradeoffs

Strengths (TCP)

  • Reliability: Guaranteed delivery with retransmissions and acknowledgments.
  • Ordering: Data arrives in the order it was sent.
  • Congestion control: Prevents network collapse and fairly shares bandwidth.
  • Universal support: Every OS, every language, every firewall understands TCP.
  • Mature tooling: Decades of debugging tools (tcpdump, Wireshark, netstat).

Strengths (UDP)

  • Low latency: No handshake overhead; first data arrives faster.
  • No HOL blocking: Lost packets don't delay other data.
  • Application flexibility: App can implement exactly the reliability semantics it needs.
  • Lower overhead: 8-byte header vs. 20+ bytes for TCP.
  • Broadcast/multicast support: UDP supports one-to-many delivery; TCP does not.

Weaknesses (TCP)

  • Connection overhead: 1.5 RTT handshake adds latency for short-lived connections.
  • HOL blocking: One lost packet blocks the entire stream.
  • Ossification: TCP is implemented in OS kernels, making protocol evolution slow.
  • Overkill for some use cases: Reliability mechanisms add unnecessary overhead for expendable data.

Weaknesses (UDP)

  • No built-in reliability: Application must handle loss, ordering, and duplication itself.
  • No congestion control: Uncontrolled UDP traffic can congest the network, potentially harming other flows.
  • Firewall challenges: Some networks block or rate-limit UDP traffic.
  • No connection state: Server must manage per-client state at the application level.

Likely Follow-Up Questions

  • What is TCP head-of-line blocking and how does QUIC solve it?
  • How does TCP congestion control work and why is BBR better than CUBIC for some workloads?
  • Why does DNS use UDP instead of TCP?
  • What is the three-way handshake and why is it necessary?
  • When would you build a custom reliability protocol on top of UDP?
  • How does QUIC achieve 0-RTT connection establishment?

Source: editorial — Synthesized from RFCs 793 (TCP), 768 (UDP), 9000 (QUIC), Google QUIC publications, and Linux kernel networking documentation.

Command Palette

Search for a command to run...