UDP and Its Use Cases#
UDP is the minimum viable transport layer: a 8-byte header on top of IP, no handshake, no retransmit, no ordering. The application picks whichever of those guarantees it actually needs.
flowchart LR
C([Client]) -->|datagram| S([Server])
C -->|datagram| S
C -->|lost datagram dropped| X[(packet loss)]
Note[no ACK, no retransmit, no order guarantee]
classDef client fill:#dbeafe,stroke:#1e40af,stroke-width:1px,color:#0f172a;
classDef service fill:#fef3c7,stroke:#92400e,stroke-width:1px,color:#0f172a;
class C client;
class S service;
classDef client fill:#dbeafe,stroke:#1e40af,stroke-width:1px,color:#0f172a;
classDef edge fill:#cffafe,stroke:#0e7490,stroke-width:1px,color:#0f172a;
classDef service fill:#fef3c7,stroke:#92400e,stroke-width:1px,color:#0f172a;
classDef datastore fill:#fee2e2,stroke:#991b1b,stroke-width:1px,color:#0f172a;
classDef cache fill:#fed7aa,stroke:#9a3412,stroke-width:1px,color:#0f172a;
classDef queue fill:#ede9fe,stroke:#5b21b6,stroke-width:1px,color:#0f172a;
classDef compute fill:#d1fae5,stroke:#065f46,stroke-width:1px,color:#0f172a;
classDef storage fill:#e5e7eb,stroke:#374151,stroke-width:1px,color:#0f172a;
classDef external fill:#fce7f3,stroke:#9d174d,stroke-width:1px,color:#0f172a;
classDef obs fill:#f3e8ff,stroke:#6b21a8,stroke-width:1px,color:#0f172a;
Use UDP when latency matters more than reliability (VoIP, real-time games), when the workload is inherently single-message (DNS, NTP), or when you want to implement your own reliability semantics (QUIC, custom RUDP).
UDP gives you addressing (ports), checksums, and nothing else. Every other transport guarantee is the application's job.
The header#
0 16 32
+--------+--------+---------+---------+
| src port | dst port |
+--------+--------+---------+---------+
| length | checksum |
+--------+--------+---------+---------+
| payload |
8 bytes of header. Compare TCP's 20 bytes plus options.
MTU and fragmentation#
A UDP datagram larger than the path MTU (typically 1500 bytes minus IP+UDP headers) gets fragmented at the IP layer. If any fragment is lost, the whole datagram is lost. Production rule: keep payloads ≤ 1400 bytes or use Path MTU Discovery.
Where UDP wins#
1. DNS#
Request-response single round trip. TCP handshake overhead would double the latency. DNS over TCP exists for replies >512 bytes (or >4096 with EDNS) and for zone transfers.
2. NTP#
Time sync. Multiple servers polled, best estimate kept. Losing one packet is fine.
3. VoIP / video calls#
A stale audio packet (200ms behind) is worse than a dropped one. RTP runs on UDP and the codec interpolates lost frames.
4. Real-time multiplayer games#
Position updates 60 times per second. Old positions are useless; just send the next one.
5. QUIC and HTTP/3#
QUIC runs on UDP because it implements its own reliability with better semantics than TCP (no head-of-line blocking, 0-RTT resumption, multipath).
6. Observability and telemetry#
Statsd, syslog, NetFlow, sFlow. Losing a metric sample is acceptable; back-pressure is not.
7. Discovery and bootstrapping#
mDNS, SSDP, DHCP - small messages over local broadcast/multicast.
Multicast and broadcast#
flowchart TB
Src[Source] -->|UDP packet| Mcast[(Multicast group<br/>224.0.0.1)]
Mcast --> R1[Receiver 1]
Mcast --> R2[Receiver 2]
Mcast --> R3[Receiver 3]
classDef client fill:#dbeafe,stroke:#1e40af,stroke-width:1px,color:#0f172a;
classDef edge fill:#cffafe,stroke:#0e7490,stroke-width:1px,color:#0f172a;
classDef service fill:#fef3c7,stroke:#92400e,stroke-width:1px,color:#0f172a;
classDef datastore fill:#fee2e2,stroke:#991b1b,stroke-width:1px,color:#0f172a;
classDef cache fill:#fed7aa,stroke:#9a3412,stroke-width:1px,color:#0f172a;
classDef queue fill:#ede9fe,stroke:#5b21b6,stroke-width:1px,color:#0f172a;
classDef compute fill:#d1fae5,stroke:#065f46,stroke-width:1px,color:#0f172a;
classDef storage fill:#e5e7eb,stroke:#374151,stroke-width:1px,color:#0f172a;
classDef external fill:#fce7f3,stroke:#9d174d,stroke-width:1px,color:#0f172a;
classDef obs fill:#f3e8ff,stroke:#6b21a8,stroke-width:1px,color:#0f172a;
UDP supports multicast and broadcast natively; TCP cannot. Used in financial market data feeds, video conferencing trees, service discovery.
Outside datacentres, multicast is rarely deployable - the public internet doesn't carry it.
Rolling reliability on UDP#
Many systems implement their own reliability over UDP because they need:
- Custom retransmit policies (FEC, sender-driven NACKs).
- Stream multiplexing without head-of-line blocking (QUIC).
- Connection migration across IP changes (mobile).
- 0-RTT resume for repeat connections.
Examples: QUIC (HTTP/3), WebRTC data channels, Mosh (shell), KCP, RUDP, RakNet.
When NOT to use UDP#
- You need ordered, complete delivery (file transfer, DB protocols).
- You want any sort of congestion control out of the box (you'll need to add it).
- You're behind enterprise firewalls that block UDP except for DNS.
Operational considerations#
- NAT traversal: UDP NAT bindings are short (30s typical). Keep alive with periodic dummy packets.
- Receive buffer: socket buffers can drop UDP packets silently under burst. Tune
SO_RCVBUF. - Source amplification attacks: open UDP services with spoofed source IPs are DDoS amplifiers (DNS, NTP, memcached). Rate-limit and authenticate.
Where UDP is the right choice#
flowchart TB
UDP((UDP))
TCP[TCP deep dive<br/>the reliable alternative]
H3[HTTP/3 + QUIC<br/>biggest UDP user]
DNS[DNS resolution<br/>top-volume UDP service]
NET[Network basics<br/>L4 placement]
TCP -. alternative .- UDP
UDP --> H3
UDP --> DNS
NET --> UDP
classDef client fill:#dbeafe,stroke:#1e40af,stroke-width:1px,color:#0f172a;
classDef edge fill:#cffafe,stroke:#0e7490,stroke-width:1px,color:#0f172a;
classDef service fill:#fef3c7,stroke:#92400e,stroke-width:1px,color:#0f172a;
classDef datastore fill:#fee2e2,stroke:#991b1b,stroke-width:1px,color:#0f172a;
classDef cache fill:#fed7aa,stroke:#9a3412,stroke-width:1px,color:#0f172a;
classDef queue fill:#ede9fe,stroke:#5b21b6,stroke-width:1px,color:#0f172a;
classDef compute fill:#d1fae5,stroke:#065f46,stroke-width:1px,color:#0f172a;
classDef storage fill:#e5e7eb,stroke:#374151,stroke-width:1px,color:#0f172a;
classDef external fill:#fce7f3,stroke:#9d174d,stroke-width:1px,color:#0f172a;
classDef obs fill:#f3e8ff,stroke:#6b21a8,stroke-width:1px,color:#0f172a;
class UDP service;
class TCP,H3,DNS,NET datastore;
Glossary & fundamentals#
| Tag | Concept | What it is | Page |
|---|---|---|---|
HLD |
Network basics | the OSI overview | network-basics |
HLD |
TCP deep dive | the reliable alternative | tcp-deep-dive |
HLD |
HTTP3 QUIC | the major UDP-based protocol | http3-quic |
HLD |
DNS resolution | the highest-volume UDP service | dns-resolution |
Quick reference#
Header#
8 bytes: src port, dst port, length, checksum.
Guarantees#
None except checksum. No ordering, no retransmit, no congestion control.
Use when#
- Single-message protocols (DNS, NTP, DHCP)
- Real-time audio / video / games
- High-throughput telemetry (statsd, syslog)
- Custom reliability needed (QUIC, WebRTC)
- Multicast required
Don't use when#
- Ordered delivery needed
- Want congestion control for free
- Behind firewalls blocking UDP
MTU rule#
Keep payload ≤ 1400 bytes to avoid IP fragmentation.
Multicast#
UDP-only feature; mostly intra-datacentre or local network.
NAT bindings#
Short timeout (30s); send keepalives.
Anti-pattern - amplification DDoS#
Open UDP service (DNS, NTP, memcached) + spoofed source = reflector attack. Mitigate with rate-limit, auth, and BCP 38.
Modern UDP#
- HTTP/3 / QUIC
- WebRTC data channels
- DNS-over-QUIC
- Custom game protocols (KCP, RakNet)
Refs#
- RFC 768
- Stevens - TCP/IP Illustrated v1
- Cloudflare QUIC posts
FAQ#
What is UDP and how is it different from TCP?#
UDP is a connectionless datagram protocol with no handshake, retransmit, or ordering. It is the bare minimum on top of IP, leaving reliability up to the application.
When should I use UDP instead of TCP?#
Use UDP when you tolerate loss for latency, like VoIP, gaming, video streaming, DNS, and metrics. Also use it when you want to build your own transport, like QUIC does.
Why is DNS over UDP?#
DNS queries fit in one datagram, complete in one round trip, and tolerate retries by the client. UDP avoids the handshake cost that would dominate query latency.
Does UDP have any reliability guarantees?#
None by default. UDP guarantees only checksum-protected datagram delivery best effort. If the application needs ordering, retransmit, or congestion control, it must build them.
How does QUIC use UDP?#
QUIC uses UDP as a thin substrate and rebuilds reliability, congestion control, encryption, and multiplexed streams in user space, free from TCP's kernel constraints.
Related Topics#
- TCP Deep Dive: the reliable alternative
- HTTP/3 and QUIC: the most important modern UDP use case
- DNS Resolution: the highest-volume UDP service on the internet