UDP & QUIC
UDP's minimal datagram service and when to use it, head-of-line blocking, and how QUIC (the basis of HTTP/3) rebuilds reliable, encrypted, multiplexed transport over UDP.
UDP (User Datagram Protocol) is TCP's minimalist sibling: it adds ports and a checksum to IP and nothing else. No connection, no reliability, no ordering, no congestion control. That sounds like a weakness, but it means applications can build exactly the behaviour they need — which is how QUIC and HTTP/3 came about.
UDP in one header
| Field | Size |
|---|---|
| Source port | 2 B |
| Destination port | 2 B |
| Length | 2 B |
| Checksum | 2 B |
That's the whole 8-byte header (TCP's is 20+). Each send is one datagram, delivered whole or not at all, possibly out of order or duplicated.
- Connection setup (1 RTT)
- Reliable, ordered byte stream
- Flow and congestion control
- Head-of-line blocking
- Web, APIs, databases, SSH, file transfer
- No setup: send immediately
- Unreliable, unordered messages
- No built-in control (be a good citizen yourself!)
- A lost packet delays nothing else
- DNS, VoIP, video calls, games, QUIC
When UDP is the right choice
- Real-time media (voice, video calls) — a late packet is useless; better to skip it than wait for a retransmission.
- Games — send the latest state 60 times a second; old state doesn't matter.
- Simple request/response — DNS queries fit in one packet; retrying at the application level is easier than a handshake.
- Broadcast and multicast — service discovery (mDNS), streaming to many receivers; TCP can't do one-to-many.
- Custom transports — QUIC, WireGuard VPN, and many others build their own reliability on UDP.
try (DatagramSocket sock = new DatagramSocket()) {
byte[] msg = "ping".getBytes();
sock.send(new DatagramPacket(msg, msg.length, InetAddress.getByName("localhost"), 9999));
byte[] buf = new byte[1500];
DatagramPacket reply = new DatagramPacket(buf, buf.length);
sock.setSoTimeout(1000); // UDP won't tell you about loss: use timeouts
sock.receive(reply);
}import socket
s = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)
s.settimeout(1.0)
s.sendto(b"ping", ("localhost", 9999))
data, addr = s.recvfrom(1500)import dgram from "node:dgram";
const s = dgram.createSocket("udp4");
s.on("message", (msg, rinfo) => console.log(`${msg} from ${rinfo.address}`));
s.send("ping", 9999, "localhost");Keep datagrams under the path MTU (~1200–1400 bytes is safe on the Internet) to avoid IP fragmentation, which hurts loss rates.
Head-of-line blocking
TCP delivers bytes strictly in order. If one segment is lost, everything after it waits for the retransmission, even data belonging to unrelated requests.
HTTP/2 multiplexes many requests over one TCP connection, which fixed HTTP/1.1's application-level head-of-line blocking but kept the transport-level one. On lossy mobile networks this can make HTTP/2 slower than several HTTP/1.1 connections.
QUIC
QUIC (standardised in 2021, RFC 9000) is a new transport that runs in user space on top of UDP. It's the foundation of HTTP/3, carrying a large and growing share of web traffic (Google, YouTube, Meta, Cloudflare).
| Feature | How it helps |
|---|---|
| Independent streams | Loss on one stream doesn't block the others — no transport head-of-line blocking |
| Built-in TLS 1.3 | Encryption is mandatory; transport and crypto handshakes combined: 1 RTT to a new server, 0-RTT when resuming |
| Connection IDs | Connections survive IP changes (connection migration): switching from Wi-Fi to 4G doesn't drop downloads |
| Encrypted headers | Middleboxes can't inspect or ossify the protocol |
| User-space implementation | Evolves with app releases instead of OS kernel upgrades |
| Better loss recovery | Unique packet numbers remove TCP's retransmission ambiguity |
Trade-offs: QUIC uses more CPU than kernel TCP (user-space processing, per-packet encryption), and some corporate networks block UDP/443, so browsers fall back to TCP.
- UDP = ports + checksum: no connection, reliability, ordering or congestion control.
- Use UDP for real-time media, games, DNS, multicast and custom transports.
- TCP's in-order delivery causes head-of-line blocking across multiplexed streams.
- QUIC (HTTP/3) runs over UDP: independent streams, built-in TLS 1.3, 1-RTT/0-RTT setup, connection migration.
QWhy does DNS use UDP?easy
Queries and answers usually fit in one packet, so a connection handshake would double the latency; the client simply retries on timeout. DNS falls back to TCP for large responses (zone transfers, big DNSSEC answers) and increasingly runs over TLS, HTTPS or QUIC for privacy.
QWhat problem does HTTP/3 solve that HTTP/2 doesn't?medium
Transport-level head-of-line blocking: with HTTP/2 over TCP, one lost packet stalls every stream. QUIC delivers streams independently. HTTP/3 also gets faster connection setup and connection migration.