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.

Intermediate 4 min readLesson 7 of 15 Interview Q&A

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

FieldSize
Source port2 B
Destination port2 B
Length2 B
Checksum2 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.

TCP
  • Connection setup (1 RTT)
  • Reliable, ordered byte stream
  • Flow and congestion control
  • Head-of-line blocking
  • Web, APIs, databases, SSH, file transfer
UDP
  • 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);
}

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.

sentappA1B1A2 ✗B2A3✓✓lostwaits…waits…
HTTP/2 over TCP: losing one packet of stream A also stalls stream B.

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).

FeatureHow it helps
Independent streamsLoss on one stream doesn't block the others — no transport head-of-line blocking
Built-in TLS 1.3Encryption is mandatory; transport and crypto handshakes combined: 1 RTT to a new server, 0-RTT when resuming
Connection IDsConnections survive IP changes (connection migration): switching from Wi-Fi to 4G doesn't drop downloads
Encrypted headersMiddleboxes can't inspect or ossify the protocol
User-space implementationEvolves with app releases instead of OS kernel upgrades
Better loss recoveryUnique packet numbers remove TCP's retransmission ambiguity
ClientServerTCP SYNSYN-ACKACK + TLS ClientHelloTLS ServerHello…HTTP request (after 2 RTTs)
TCP + TLS 1.3: two round trips before the request. QUIC: one (or zero when resuming).

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.

Key takeaways
  • 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.
Interview questions
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.