Free — no signup required

TCP vs. UDP: The Fundamental Choice

3 min read

Certified Mail vs. a Postcard

At the Transport Layer, every application that sends data across a network must make a foundational choice: use TCP (Transmission Control Protocol) or UDP (User Datagram Protocol). This choice determines whether the network connection prioritizes reliability or speed.

TCP — The Reliable One
Think of TCP as sending an important legal document via certified mail with return receipt requested. The postal service confirms the letter was delivered, and if it gets lost, they resend it. TCP works the same way:

  • Connection-oriented: A formal connection must be established before any data flows (more on this in the next section).
  • Reliable delivery: Every packet is acknowledged. If a packet is lost in transit, TCP detects the missing acknowledgment and retransmits the data automatically.
  • Ordered: Data arrives at the destination in exactly the same order it was sent, even if individual packets took different routes through the network.
  • Flow and congestion control: TCP actively manages how fast data is sent to avoid overwhelming the receiver or the network.
  • Overhead: All this bookkeeping costs time and CPU cycles.

TCP is used wherever correctness matters more than raw speed: web browsing (HTTP/HTTPS), email (SMTP), file transfers (FTP/SFTP), and remote shell access (SSH).

UDP — The Fast One
Think of UDP as dropping a postcard in a mailbox. You write the address, drop it in, and walk away. You have no idea if it arrived, and there is no mechanism to find out. UDP works the same way:

  • Connectionless: No setup handshake. Data is sent immediately.
  • No guaranteed delivery: Packets can be lost, and the sender will never know.
  • No ordering: Three packets sent in sequence may arrive in any order.
  • Minimal overhead: The UDP header is only 8 bytes versus TCP's 20+ bytes. This makes UDP extremely fast.

UDP is used wherever speed matters more than occasional data loss: live video streaming, Voice over IP (VoIP), online gaming (where a stale position update is worthless anyway), and DNS lookups (small, fast queries where a retry is cheap).

Interview Tip

Interviewers frequently ask: "Why would you ever choose an unreliable protocol?" The answer is nuanced. UDP is not "unreliable" in a careless sense — it is deliberately lightweight. Applications that use UDP often implement their own reliability mechanisms at the application layer, tuned specifically to their needs. QUIC (covered later in this lesson) is the best modern example: it is built on UDP but implements its own ordering and retransmission logic, outperforming TCP in many real-world scenarios.

Key Point: The choice between TCP and UDP is a trade-off between correctness and latency. Neither is universally better. The right answer depends entirely on what the application can tolerate losing.

This is one of 18 chapters

Every chapter is free — Kubernetes, Terraform, SRE, distributed systems, and more — with fast daily review built in.

Sign up free