UDP (User Datagram Protocol)
A lightweight, connectionless networking protocol that prioritizes speed over reliability.
Detailed Explanation
Unlike TCP, UDP does not check if data arrived or in what order. It just 'fires and forgets.' This makes it ideal for real-time applications where a tiny bit of data loss is better than a delay (latency), such as video conferencing, online gaming, and live streaming. It is also the basis for the new HTTP/3 protocol.
Quick Summary
UDP sends packets without setup or guarantees, no handshake, no retries, no ordering. That's the bug and the feature: it's the fastest way to move bytes, ideal where stale data is worse than lost data.
Key Takeaways
- No connection, no handshake, every packet stands alone.
- No retransmission, no ordering, the application handles whatever reliability it needs.
- Header is 8 bytes vs. TCP's 20; less overhead per packet.
- Powers DNS, NTP, gaming, voice/video, and now QUIC/HTTP/3.
- Trivially spoofable source addresses make UDP a favorite for reflection/amplification DDoS attacks.
When to use it
- Real-time media: VoIP, video conferencing, live game state updates.
- DNS queries, a quick request/response that's cheaper than opening a TCP connection.
- Service discovery and gossip protocols inside a datacenter.
- QUIC and HTTP/3, which build their own reliability on top of UDP to bypass TCP head-of-line blocking.
Common Mistakes
- Assuming "UDP is faster than TCP" universally, without handshake, yes; once you add your own reliability layer, often not.
- Sending packets larger than the path MTU (~1400 bytes); fragmentation kills performance and many firewalls drop fragments.
- Trusting source IP on UDP packets; spoofing is trivial.
- Forgetting that home and enterprise NATs are sometimes hostile to UDP, TCP fallbacks are still important.
UDP (User Datagram Protocol), Frequently Asked
Why is HTTP/3 on UDP if UDP is unreliable?
Because QUIC layers reliability and ordering on top, while sidestepping TCP's head-of-line blocking, a single lost packet in TCP stalls every stream sharing that connection. UDP lets QUIC do per-stream loss recovery.
When should I pick UDP over TCP for a new protocol?
When latency matters more than completeness (live media, real-time games) or you need application-controlled retransmission semantics. Otherwise default to TCP, its reliability is hard to replicate well.