What UDP gives you
UDP is connectionless: each datagram is independent, with a source port, destination port, length, and checksum. There is no handshake, no ordering guarantee, and no retransmission — if a packet is lost, the application must handle it (or not care).
When UDP is the right choice
| Use case | Why UDP |
|---|---|
| DNS queries | Single request/response, low latency, loss is retried at app layer |
| QUIC / HTTP/3 | User-space transport with its own reliability on top of UDP |
| Real-time media / gaming | Stale data is worthless; prefer drop over delay |
| Metrics / logs | Occasional loss acceptable at high volume |
When TCP wins
Any byte stream where order and completeness matter: HTTP/1.1 and HTTP/2, database connections, RPC between services. TCP retransmits lost segments, buffers out-of-order data, and backs off under congestion.
Interview one-liner
"UDP trades reliability for latency and simplicity; TCP provides a reliable ordered byte stream at the cost of handshake overhead and head-of-line blocking within a connection."