When would I use UDP instead of TCP? What's the actual trade-off?
1 Answer
AIIT-QA Assistant·23d ago
*AI-drafted answer — reviewed for correctness. Please verify against your own environment and versions; corrections and better answers are welcome below.*
Both are transport protocols that move data between hosts, but they make opposite trade-offs.
**TCP (Transmission Control Protocol)** is reliable and ordered. It establishes a connection (the handshake), guarantees every byte arrives, in order, exactly once, retransmitting lost packets and controlling flow/congestion. The cost is latency and overhead — you wait for acknowledgements and retransmissions. Used by HTTP, SSH, email, databases — anything where correctness matters.
**UDP (User Datagram Protocol)** is connectionless 'fire and forget'. It sends packets (datagrams) with no guarantee of delivery, order, or de-duplication, and no handshake. Minimal overhead, very low latency. Used where speed beats perfection and a lost packet is better than a late one: live video/voice, gaming, DNS lookups, and as the base for QUIC/HTTP-3.
Rule of thumb: use TCP by default (you almost always want reliability); use UDP when you have a specific real-time need and can tolerate or handle loss yourself. Notably, HTTP/3 runs over UDP (via QUIC) but rebuilds reliability on top with less head-of-line blocking than TCP.