DEV Community

Cover image for TCP vs UDP: When to Choose Reliability or Low Latency (Quick Guide)
Long Nguyen
Long Nguyen

Posted on

TCP vs UDP: When to Choose Reliability or Low Latency (Quick Guide)

Quick primer for developers and ops: TCP vs UDP explained so you can pick the right transport for your app.

Why it matters

  • TCP = connection-oriented, reliable, ordered byte stream (retransmits, flow/congestion control).
  • UDP = connectionless, message-oriented, low overhead and lower latency but no built-in reliability or ordering.

When to use each (practical rules)

  • Pick TCP when correctness matters: web (HTTP/HTTPS), file transfers, APIs, SSH, email.
  • Pick UDP when low latency or real-time delivery matters and occasional loss is acceptable: VoIP, live video, online games, real-time telemetry.
  • Consider hybrid options: DNS commonly uses UDP but falls back to TCP for larger responses; QUIC (modern HTTP/3) runs over UDP to combine low-latency with reliability.

Common protocol & port examples

  • TCP: HTTP (80), HTTPS (443), SSH (22), SMTP (25), FTP (21)
  • UDP: DNS (53), SIP (5060), RTP (audio/video streams), many game servers (varies)

Quick decision checklist

  • Need ordered, guaranteed delivery? → TCP
  • Need minimal latency and can tolerate packet loss? → UDP
  • Behind NAT/firewall or need congestion control? Consider TCP or a higher-level protocol built on UDP (e.g., QUIC).

Want a concise comparison table, diagrams of handshake vs datagram flow, and real-world troubleshooting tips?

Read the full TCP vs UDP guide on Netalith

Top comments (0)