UDP — User Datagram Protocol
UDP is the connectionless, unreliable, fastest transport in the IP family. You hand it a datagram, it sends it, and that is the entire contract. No handshake, no retransmission, no ordering, no flow control. This makes UDP the right choice when late data is worse than missing data — voice, video, gaming, DNS — and the foundation on which modern transports like QUIC and WebRTC are built.
How it works
UDP is the minimalist transport. Its header is 8 bytes — source port, destination port, length, checksum. There is no sequence number, no ack, no window, no congestion state. You call sendto() and the kernel fires a datagram at the network. The kernel does not know if it arrived. The kernel does not know if datagrams arrived in order. The kernel does not even know if the destination is alive.
This sounds bad, but it is exactly what some workloads need. The cost of TCP's guarantees is latency: every byte must wait for its turn (ordering), the sender must wait for acks (reliability), the connection must slow down on loss (congestion control). For a workload where stale data is useless — a video frame from 200ms ago, a game position update from 100ms ago — these guarantees are pure overhead. Better to drop the stale packet and move on.
The canonical UDP use cases share one trait: late data is worse than missing data.
DNS. A query is one datagram; the response is one datagram. If it does not arrive, the resolver retries. There is no value in TCP's reliability here — you would pay 1 RTT of handshake for a request that is itself one RTT. (DNS does fall back to TCP for large responses over 512 bytes or for zone transfers, but the default is UDP.)
Voice and video. A video call sends 30-60 frames per second. If frame 47 is lost, the player interpolates from frame 46 and 48 — the user sees a brief glitch, not a stalled call. Retransmitting frame 47 would make it arrive 100ms late, which is useless and consumes bandwidth competing with the current frame. UDP lets the codec fire-and-forget; modern codecs (Opus, VP8, H.264) are designed to tolerate loss.
Online games. A shooter's player position updates 20-60 times per second. The current position is all that matters; an old position is not just useless, it would be wrong to display it. UDP lets the server send the latest position; the client uses whatever arrives and ignores gaps.
Live streaming. RTP, SRT, and similar protocols run over UDP for the same reason: late frames are useless, and the bandwidth saved by not retransmitting is better spent on the next frame.
Application-level transports. QUIC (HTTP/3) and WebRTC both run over UDP because they need to implement their own reliability semantics that the kernel's TCP cannot provide: per-stream reliability, 0-RTT setup, connection migration across networks, and custom congestion control optimized for the application.
UDP itself is unreliable, but many UDP-based protocols add back exactly the reliability they need — and nothing more. This is the key insight: reliability is not binary, it is shaped to the workload.
- TFTP adds simple stop-and-wait ACKs for file transfer.
- QUIC adds selective ACKs, per-stream retransmission, and CUBIC/BBR congestion control — essentially rebuilding TCP but with independent streams.
- WebRTC adds NACK (negative acknowledgements), FEC (forward error correction), and bandwidth estimation tuned for real-time media.
- DNS over UDP adds 'just retry the whole query' — the simplest possible reliability.
The reason these protocols do not just use TCP is that they need control over what gets retransmitted. TCP retransmits everything, in order, blocking everything behind it. A real-time protocol wants to retransmit the latest I-frame in a video stream, skip the stale P-frames, and keep the audio stream flowing — priorities TCP cannot express.
The cost is complexity. Building reliability on UDP means you are now responsible for sequence numbers, retransmission timers, congestion control, and security (DTLS, since you cannot use TLS directly over UDP). QUIC is roughly the size of TCP and TLS combined — it is not a 'simpler' protocol. It is a protocol that gives the application the freedom to make different trade-offs than TCP made in 1988.
Many corporate firewalls and NATs treat UDP with suspicion. They allow outbound TCP 443 by default but block or rate-limit UDP because it is stateless and historically associated with amplification attacks. This is why QUIC falls back to TCP in some networks, and why WebRTC needs TURN servers. The lesson: deploying a UDP-based protocol in the wild is not just a protocol design problem — it is a deployment problem.
Two practical consequences every engineer should internalize about UDP.
First, a naive UDP sender is dangerous. Unlike TCP, UDP has no congestion control built in. If your application just sends as fast as it can, you will saturate the link and starve TCP flows (TCP backs off, UDP does not). This is exactly what caused the 1986 internet congestion collapse and why Van Jacobson added congestion control to TCP. Modern UDP-based protocols — QUIC, WebRTC, RTSP — all implement their own congestion control (often BBR or GCC). If you build a custom UDP protocol without one, you are committing a network crime.
Second, UDP datagrams have a size limit you must respect. The theoretical max is 65507 bytes (the UDP length field minus header), but in practice anything over the path MTU (typically ~1500 bytes after IP+UDP headers, so ~1472 bytes of payload) gets fragmented at the IP layer. Fragments that lose any piece are discarded wholesale — a 1473-byte datagram sent as two fragments has roughly 2x the loss probability of a 1472-byte datagram sent whole. Production UDP protocols stay under the MTU (often 1200 bytes to be safe across all path MTUs) or implement their own segmentation and reassembly (which is what QUIC does, with its own per-stream frame boundaries).
These two facts shape every real UDP deployment. DNS stays tiny (one datagram, one response). Voice uses small packets (20ms of Opus audio is ~80 bytes) so loss is fine and bandwidth is cheap. Video uses larger packets but accepts that losing one means losing a frame, not a stream. QUIC keeps packets under MTU and implements its own congestion control. The pattern: UDP gives you a sharp tool; you have to wield it with discipline.
Why does DNS use UDP by default rather than TCP for typical queries?
Pick one answer.
You are building a real-time multiplayer game server. Why is UDP the right transport, and what reliability do you add on top?
Pick one answer.
Which is NOT a reason HTTP/3 chose to run over QUIC (which is UDP) instead of TCP?
Pick one answer.
| Property | TCP | UDP |
|---|---|---|
| Header size | 20+ bytes (with options) | 8 bytes (fixed) |
| Connection model | Connection-oriented (3-way handshake) | Connectionless (fire-and-forget) |
| Setup latency | 1 RTT before first byte | 0 RTT (immediate) |
| Reliability | Guaranteed delivery (ACKs + retransmission) | Best-effort (may be lost, duplicated, reordered) |
| Ordering | In-order delivery | No ordering guarantee |
| Flow control | Sliding window | None |
| Congestion control | Built-in (CUBIC, BBR) | None — application must implement |
| Head-of-line blocking | Yes — lost packet stalls all later packets | No — each datagram independent |
| Stream multiplexing | One stream per connection (HTTP/2 works around this) | Each datagram independent (QUIC uses this for per-stream reliability) |
| Multicast / broadcast | No (point-to-point only) | Yes (one-to-many native) |
| Typical uses | Web, email, file transfer, RPC | DNS, voice/video, gaming, QUIC/HTTP/3 |
Google began deploying QUIC (a UDP-based transport that rebuilds TCP+TLS semantics with per-stream reliability and 0-RTT setup) on youtube.com in 2013. They reported (IETF 97, 2016) that QUIC reduced video rebuffering by 30% on YouTube and cut search latency by 8% on mobile — specifically because per-stream reliability eliminated the head-of-line blocking where one lost packet stalled every multiplexed HTTP/2 stream. By 2023, ~25% of all internet traffic runs over QUIC. The lesson: UDP is not 'faster than TCP' — it's a substrate on which an application can build exactly the reliability it needs. QUIC is essentially the size of TCP+TLS combined; the win is that the application, not the kernel, controls the trade-offs.
UDP failure scenarios — what breaks in production.
(1) Amplification attack. DNS over UDP is the textbook example: a 60-byte spoofed query triggers a 4000-byte DNSSEC response, ~70x amplification. The attacker forges the source IP to be the victim's; DNS resolvers worldwide pummel the victim. Mitigation: DNS Cookies (RFC 7873), rate-limiting per source IP, and response-size limits.
(2) NAT timeout mid-call. Home NAT boxes expire UDP mappings after 30 seconds of inactivity. A video call that pauses audio for 60 seconds (mute, hold) loses its NAT mapping — audio never returns even when unmuted. This is why every WebRTC client sends STUN keepalives every 20 seconds, and why your video call occasionally needs to be re-initiated.
(3) Path MTU surprises. A 1473-byte UDP datagram fragments at the IP layer into two fragments. If either fragment is lost, the entire datagram is dropped — so a 0.5% per-fragment loss rate becomes a ~1% datagram loss rate, doubling effective loss. Modern QUIC implementations aggressively stay under 1200 bytes per packet to avoid fragmentation across path-MTU-discovered paths.
(4) No congestion control collapses the network. A naive UDP video sender that does not implement BBR or CUBIC will saturate the bottleneck link and starve TCP traffic (which DOES back off). This is the 1986 internet congestion collapse pattern, repeated in modern clothes — it's why every production UDP protocol (QUIC, WebRTC, RTSP) ships with its own congestion control.
(5) Corporate firewall blocking. Many enterprises allow TCP 443 by default but block or rate-limit UDP. A QUIC deployment without TCP fallback will silently fail for 10-20% of corporate users. This is why browsers fall back to HTTP/2 over TCP when QUIC fails — and why 'we run on UDP' is a deployment problem, not just a protocol choice.
UDP scaling implications.
UDP scales to enormous aggregate throughput because the kernel keeps no per-connection state. A single Linux box can service hundreds of thousands of concurrent DNS queries per second because each query is one datagram in, one out, with no handshake, no retransmission buffer, no congestion window. Compare to TCP: each connection requires kernel memory for send/receive buffers, congestion state, and timers — typically 10-50 KB per connection, which caps a single machine at ~100K-1M concurrent connections (the well-known C10K problem, extended to C1M).
This is exactly why DNS resolvers, NTP servers, and QUIC terminators can handle millions of concurrent clients on modest hardware. It's also why Redis (single-threaded, in-memory, custom protocol) used to support UDP for sub-millisecond lookups before deprecating it for security reasons.
But the scaling advantage disappears the moment you implement reliability on top. A QUIC terminator that tracks per-stream ACK state and retransmission buffers uses kernel-or-userspace memory similar to a TCP terminator. The 'UDP is more scalable' truth only holds for fire-and-forget workloads: DNS, syslog, SNMP traps, VoIP keepalives. For everything else, UDP is a substrate that lets the application choose its scaling trade-offs — but the application then has to actually make those choices.
A product team is choosing between HTTP/2 (over TCP) and HTTP/3 (over QUIC, which runs over UDP) for a media-heavy web app with significant mobile users on flaky cellular networks. Which benefit most directly justifies choosing HTTP/3?
Pick one answer.
Engineering mental model
Mental model. Think of UDP — User Datagram Protocol as a deliberate boundary in a system. The boundary exists because something becomes harder to manage when everything is done in one place: latency, scale, failure isolation, consistency, cost, or team ownership. The useful question is not “what does UDP — User Datagram Protocol mean?” but “what pressure makes this boundary worth introducing, and what new failure mode does it create?”
Before choosing UDP — User Datagram Protocol, name the workload, the critical user path, the dominant bottleneck, the failure you are trying to absorb, and the trade-off you are willing to accept. If you cannot name those five things, the design is probably premature.
// Pseudocode
request = receive()
result = udp(request)
return result
// Production questions:
// 1. What happens on timeout?
// 2. Can this operation be retried safely?
// 3. What is the bottleneck?Back-of-the-envelope reasoning
Numerical lens: write down traffic, payload size, read/write ratio, peak multiplier and durability target before choosing a component. The numbers should justify the architecture.
Interactive thought experiment: UDP — User Datagram Protocol
Change the variables below and predict what breaks first in UDP — User Datagram Protocol. The production lab can later reuse these same inputs.
Change one variable at a time. Predict the failure mode first, then move the slider and see whether your mental model matches the simplified system response.
If you are stuck on UDP — User Datagram Protocol, start by drawing the request path and marking every network hop, stateful component, queue, cache and failure boundary. Then estimate where the system will saturate.
You increase traffic by 10× in a system using UDP — User Datagram Protocol. What should you inspect first?
Pick one answer.
Which statement is the safest engineering habit when using UDP — User Datagram Protocol?
Pick one answer.
You have dashboards for traffic, latency, errors and saturation. You can change the architecture, but every change has operational cost.
Production scenario: your system uses UDP — User Datagram Protocol, traffic suddenly spikes, and p99 latency doubles. What is your first move?
Interview drill
Answer this without notes: When would you choose UDP — User Datagram Protocol, and when would you intentionally avoid it? Mention at least one bottleneck it addresses, one failure mode it introduces, and one alternative. Then quantify the workload you are designing for.
A useful engineering lens for UDP - User Datagram Protocol: define the problem it solves, the simpler design that fails first, the constraint that forces you to introduce this concept, and the new failure modes the concept creates.
Numerical sanity check
Back-of-the-envelope reasoning beats fake precision. State your traffic, payload, concurrency and growth assumptions explicitly, then calculate enough to know whether the current architecture is orders of magnitude away from the target.
Do not optimize for a memorized definition. Reason from the workload and failure mode.
Imagine the simplest version of a system using UDP - User Datagram Protocol. What breaks first as traffic grows by 10×, and what would you change before reaching 100×?
Pick one answer.
What you gain, what you pay
- +No handshake — zero setup latency, ideal for short request-response like DNS.
- +No head-of-line blocking — lost datagrams do not stall later ones.
- +Application controls reliability — ship exactly what the workload needs, no more.
- +Smaller header (8 bytes) and lower per-packet overhead than TCP.
- +Enables multicast and broadcast — TCP is strictly point-to-point.
- −Unreliable by default — the application must add reliability if it needs it.
- −No congestion control — a naive UDP sender can collapse the network (a real concern for video).
- −Many firewalls and NATs treat UDP with suspicion — deployment headaches.
- −Building reliability correctly is hard (sequence numbers, retransmission timers, congestion control, security).
- −Cannot use TLS directly — must use DTLS, which is more complex.
How this breaks in production
- Sending UDP without congestion control and collapsing the network — the original 1986 internet congestion collapse, in modern clothes.
- Assuming datagrams arrive in order — they do not, ever.
- Assuming datagrams arrive at all — they can be silently dropped by any router or firewall.
- Fragmenting large UDP datagrams (>MTU) and losing the reassembly when one fragment drops.
- Hitting middlebox UDP timeouts — NATs kill idle UDP flows; the application must keepalive.
- Amplification attacks — a small UDP request triggers a huge response (DNS amplification); mitigated by rate limiting and response cookies.
Don't fall into these traps
- •Using UDP 'because it is faster' without adding reliability when the workload actually needs it.
- •Using TCP for real-time media and being confused by the latency floor.
- •Forgetting to implement congestion control in custom UDP protocols — a single video sender can DoS a network.
- •Sending large datagrams (>1400 bytes) without thinking about fragmentation and MTU.
- •Assuming UDP will pass through corporate firewalls — plan a TCP fallback.
- •Ignoring security — UDP is trivially spoofable; use DTLS or signed datagrams.
Real systems using this
How real systems implement this
- DNS — Standard queries over UDP port 53 — one datagram in, one out. Falls back to TCP for large responses or zone transfers.
- QUIC / HTTP/3 — Implements TCP-equivalent reliability (plus TLS) on top of UDP to enable per-stream reliability, 0-RTT setup, and connection migration. Now carries a large fraction of Google and Cloudflare traffic.
- WebRTC — Peer-to-peer voice, video, and data channels over UDP. Adds NACK, FEC, and bandwidth estimation tuned for sub-second latency. Requires STUN/TURN for NAT traversal.
Practice saying it out loud
- Q1When would you choose UDP over TCP? Give three real-world examples and explain why each benefits from UDP.
- Q2If UDP is unreliable, how can a DNS query be trustworthy? Walk through the reliability model.
- Q3You are building a video conferencing product. Why UDP, and what reliability do you add on top?
- Q4Why does HTTP/3 move from TCP to UDP-based QUIC? What does QUIC do that TCP cannot?
- Q5What are the deployment risks of running a UDP service, and how would you mitigate them?
Further reading & references
Core explanations are original NO CAP material. External references are provided for deeper study and standards.
What next?
Mark as understood once the mental model clicks.
Next recommended
QUIC — The UDP Transport Powering HTTP/3