Blog

When Throwing Away Reliability Is the Right Call: UDP in Practice

UDP gives up ordering, retransmission, and connections in exchange for raw speed and control, making it the right tool for a surprisingly large class of systems.

March 28, 20266 min readMuhammad Shehzaib
NETWORKINGPROTOCOLSUDPLATENCY

If TCP is the careful protocol that guarantees delivery, UDP is the one that shrugs and sends the packet anyway. UDP, the User Datagram Protocol, is almost the thinnest possible layer over IP: it adds source and destination ports, a length, and an optional checksum, and that is essentially all. There is no handshake, no acknowledgment, no retransmission, no ordering, and no congestion control. A packet either arrives or it does not, and your application is responsible for everything else. To a backend developer raised on reliable streams this can feel reckless, but UDP underpins DNS, real-time media, gaming, QUIC, and most modern observability pipelines. The skill is knowing when reliability is worth its latency cost and when you genuinely want to control delivery semantics yourself rather than defer to the kernel's TCP machinery.

What UDP Actually Provides

A UDP datagram has an eight-byte header: a source port, a destination port, a length, and a checksum. That is the entire protocol. There is no concept of a connection, so there is no state to set up or tear down and no sequence numbers tracking which bytes arrived. Each datagram is independent; the kernel hands your application whole messages rather than a byte stream, which means message boundaries are preserved exactly as you sent them. The checksum lets the receiver detect corruption and discard a damaged datagram, but nothing requests a replacement. Because there is no per-connection bookkeeping, a single UDP socket can receive datagrams from many different senders, and you read the sender's address with each message. This statelessness is precisely what makes UDP cheap, scalable, and suitable for one-to-many patterns that TCP cannot express.

No Connection, No Handshake

Because UDP has no handshake, the very first datagram carries real data with zero setup round trips. For a DNS query that resolves in a single request and response, paying TCP's one and a half round trip handshake before sending anything would more than double the latency. UDP simply fires the query and waits for an answer. This also means there is no connection state consuming memory on a server, so a single process can field requests from millions of clients without a per-client socket. The flip side is that the application must handle everything the handshake would have established: detecting a missing reply, deciding when to retransmit, and dealing with duplicate or reordered datagrams. For request-response patterns that are naturally idempotent and small, that burden is light, which is why DNS chose UDP first and falls back to TCP only for large answers.

Latency Over Reliability

TCP's reliability has a hidden cost called head-of-line blocking. If one segment is lost, every later byte waits in the kernel buffer until the missing one is retransmitted, even if those later bytes already arrived. For a live video call or a multiplayer game, a packet that arrives late is worthless: by the time it is retransmitted, the moment has passed and a newer frame is already available. UDP lets the application say I would rather have fresh data with an occasional gap than perfectly ordered data that is stale. Voice and video codecs are built to conceal small losses gracefully, interpolating over a missing frame rather than stalling. This is the core trade: TCP optimizes for completeness, UDP optimizes for timeliness, and for real-time media timeliness is the entire point of the system.

Building Reliability Yourself

Choosing UDP does not force you to abandon reliability; it lets you implement exactly the reliability you need. Many systems layer their own lightweight scheme on top: sequence numbers to detect loss and reordering, selective acknowledgments for only the packets that matter, and application-aware retransmission that resends a critical state update but skips a stale position report. A game server might guarantee delivery of a player death event while letting routine movement packets drop, something TCP cannot express because it treats all bytes identically. QUIC is the most prominent example of this philosophy, building full reliability, multiplexed streams, and encryption directly over UDP. The lesson is that UDP is not the absence of reliability but the freedom to define it, accepting more application complexity in exchange for control that a one-size-fits-all transport simply cannot offer.

Where UDP Wins Clearly

Several workloads map naturally onto UDP. DNS uses it for the overwhelming majority of lookups because queries are tiny and a lost query is cheap to retry. Real-time media over RTP, including most voice and video conferencing, relies on it to keep latency low. Online games send frequent state updates where freshness beats completeness. Metrics and logging systems like the classic statsd protocol fire fire-and-forget datagrams so that telemetry never blocks or slows the application emitting it. NTP synchronizes clocks with single-datagram exchanges. Service discovery and multicast or broadcast scenarios, where one sender addresses many receivers at once, are only possible with UDP since TCP is strictly point-to-point. In each case the common thread is small, independent messages where the cost of a lost one is low and the cost of waiting is high.

Where UDP Hurts You

UDP is the wrong choice when you need every byte delivered in order and cannot tolerate gaps. File transfers, database connections, API calls returning structured payloads, and anything resembling a reliable byte stream belong on TCP, because reimplementing ordered reliable delivery correctly is genuinely hard and easy to get subtly wrong. UDP also offers no built-in congestion control, so a careless UDP application can flood a network and harm other traffic, including its own. Datagrams larger than the path maximum transmission unit get fragmented at the IP layer, and if any fragment is lost the entire datagram is discarded, so large UDP messages are fragile. Finally, because UDP is connectionless and trivially spoofed, it is a favorite vector for amplification attacks, where a small forged request triggers a large response aimed at a victim. These risks demand deliberate design.

QUIC And The Modern Shift

The most important recent development is QUIC, the transport beneath HTTP/3, which runs entirely over UDP. This surprises many engineers who assume UDP is only for media, but the choice is deliberate. TCP is implemented in the operating system kernel and evolves slowly, while building a new transport on UDP lets it live in user space and ship with the application, so improvements deploy at software speed. QUIC provides reliable, ordered, encrypted, multiplexed streams, but because each stream is independent, a lost packet only blocks the one stream it belongs to rather than the whole connection, eliminating TCP's head-of-line blocking across requests. It also merges the transport and TLS handshakes, often establishing a secure connection in a single round trip. QUIC shows UDP as a foundation to build on, not merely a fast-and-loose alternative.

Choosing In Your Backend

As a backend developer the decision is rarely yours to make at the socket level for typical web work, because your HTTP framework and database drivers already sit on TCP, which is correct for request-response APIs and persistent data connections. UDP becomes relevant when you build or operate something specialized: a metrics pipeline, a real-time feature with WebRTC, a custom service-discovery mechanism, or a high-throughput ingestion endpoint where occasional loss is acceptable. Ask three questions. Does every message need guaranteed in-order delivery, or is freshness more valuable? Are messages small and independent, or part of a long stream? Can you tolerate implementing your own retransmission and congestion handling? If reliability and ordering are non-negotiable, reach for TCP. If low latency, statelessness, or one-to-many delivery dominate your requirements, UDP earns its place.