TCP vs UDP: When to Use Which

The Core Trade-off

TCP guarantees reliable, ordered delivery at the cost of extra overhead and latency. UDP is fast and lightweight, but leaves reliability entirely up to the application, if it needs it at all. Choosing between them means deciding which of those two properties actually matters more for a given task.

Side-by-Side Comparison

TCPUDP
ConnectionRequires a handshake firstNone - just send
ReliabilityGuaranteed delivery, retransmits lost dataNo guarantee - lost data stays lost
OrderingData arrives in the order it was sentNo ordering guarantee
SpeedSlower, due to handshakes and acknowledgmentsFaster, minimal overhead
Typical usesWeb pages, file transfers, emailVideo calls, gaming, DNS

A Simple Way to Decide

  • Does losing or reordering a piece of data break the whole thing? A corrupted file is unusable - choose TCP.
  • Is slightly stale or missing data acceptable if it means staying fast? A dropped video frame is barely noticeable - choose UDP.
  • Does the application already handle its own retries? DNS resolvers retry on their own, so UDP's simplicity is preferred there.

When Applications Add Their Own Reliability on Top of UDP

Some modern protocols (like QUIC, which underlies HTTP/3, covered in a later note) use UDP as their base but implement their own custom reliability and ordering logic on top of it - getting UDP's speed while still selectively guaranteeing delivery where it actually matters.

Written by Lorens Mishra

Software Engineer Notes Management System Administrator

Discussion

0 comments
Sign in to join the discussion.

No comments yet. Be the first to say something.