Vibe Engines is free, interactive AI engineering & system design — runs in your browser. Pick a learning path →
TCP vs UDP: guaranteed delivery, or raw speed?
Both carry your data across the internet, but they make opposite promises. TCP swears every byte arrives, in order, no matter what — and pays for that promise in latency. UDP promises nothing and just throws packets at the wire — which, for a live video call, turns out to be exactly what you want.
The one distinction that decides everything
TCP is connection-oriented and reliable: it opens a connection with a handshake, numbers every byte, acknowledges what arrives, retransmits what doesn’t, and delivers the stream to the application in order — with flow and congestion control so it doesn’t overwhelm the receiver or the network. UDP is connectionless and best-effort: it wraps your data in a tiny header and fires it off with no handshake, no acknowledgements, no retransmission, and no ordering. If a UDP packet is lost or arrives out of order, the protocol neither knows nor cares — that’s the application’s problem, if it’s a problem at all.
If every byte must arrive intact and in order (a web page, a file, an email), you want TCP’s guarantees. If low latency matters more than completeness and a lost packet is better dropped than resent late (live audio, video, gaming), you want UDP’s speed.
Head to head
| Dimension | TCP | UDP |
|---|---|---|
| Connection | Handshake, stateful connection | Connectionless — just send |
| Reliability | Guaranteed — ACKs + retransmit | None — packets may vanish |
| Ordering | In-order delivery guaranteed | No ordering — may arrive shuffled |
| Flow / congestion control | Yes — adapts to receiver & network | No — sends as fast as you ask |
| Header overhead | Larger (20+ bytes, more state) | Tiny (8 bytes) |
| Latency | Higher — handshake, ACKs, retransmit waits | Lower — no waiting on delivery |
| On packet loss | Stalls to retransmit (head-of-line blocking) | Drops it and keeps going |
| Typical use | HTTP, email, file transfer, DB connections | Video/voice, gaming, DNS, streaming |
When to use each
Reach for TCP
- Web traffic (HTTP/HTTPS), APIs, anything request/response
- File transfer, email, database connections
- Any payload where a single missing byte corrupts the result
- When you want reliability handled for you, for free
- Long-lived connections that can absorb handshake cost
Reach for UDP
- Live audio and video, VoIP, video calls
- Online gaming — position updates where stale data is useless
- DNS lookups — one small request/response, retry if needed
- Real-time telemetry and streaming where latency rules
- When your app can tolerate (or handle) its own loss
The modern answer: reliability built on UDP (QUIC)
The two aren’t a permanent fork. Modern transport increasingly builds the reliability it needs on top of UDP rather than using TCP. QUIC — the transport under HTTP/3 — runs over UDP and re-implements connection setup, reliability and congestion control in user space, so it gets TCP-grade guarantees while dodging TCP’s baked-in limitations (notably head-of-line blocking, below) and enabling faster connection setup. So "TCP vs UDP" at the app layer is often really "a reliable protocol vs a bare one," and UDP has quietly become the flexible foundation that new reliable protocols are built on.
For ordinary request/response traffic, use TCP (or HTTP over it) — reliability for free, and it’s what everything speaks. Reach for UDP when you have a specific, measured need for low latency over completeness, or when you’re building a real-time protocol and want to control reliability yourself.
Head-of-line blocking: why real-time picks UDP
TCP’s in-order guarantee has a sharp edge called head-of-line blocking. Because TCP must hand bytes to the application in order, a single lost packet stalls everything behind it: the receiver has the later packets buffered but can’t deliver them until the missing one is retransmitted and arrives. For a file, that’s fine — you wait a few milliseconds. For a live video call, it’s a disaster: the frame you’re stuck waiting to retransmit is already stale by the time it arrives, and meanwhile the picture freezes.
UDP has no such rule. If a packet is lost, the ones after it are delivered immediately, and the app simply skips the missing audio sample or video frame — a tiny glitch nobody notices, versus a frozen call everybody hates. That’s the core reason real-time media runs on UDP: for live data, late is worse than lost. (And it’s exactly the blocking QUIC was designed to eliminate by multiplexing independent streams over UDP, so a loss in one stream doesn’t stall the others.)
TCP trades latency for the guarantee that nothing is missing or misordered. UDP trades that guarantee for the ability to never wait — which is priceless when stale data is worthless and glitches are cheaper than freezes.
A worked scenario: loading a page vs a video call
Loading this web page is a TCP job. The HTML, CSS and JavaScript must arrive complete and in order — a single dropped byte in a script breaks it, and there’s no such thing as "skip the missing part of the file." TCP’s handshake and retransmission cost a few milliseconds you won’t notice, and in exchange you get a perfect copy of every resource. This is why the web runs on TCP (and QUIC, its UDP-based successor).
A video call is a UDP job. Frames of audio and video pour in dozens of times a second, and if one packet drops, you do not want the protocol to freeze the call while it fetches a now-useless old frame — you want it to skip that frame and keep the conversation live. A momentary blip is invisible; a two-second freeze while TCP retransmits is maddening. So the app sends over UDP and accepts (or conceals) the occasional loss. Same internet, opposite protocol, because one payload must be perfect and the other must be prompt.
Must-be-complete, order-sensitive data → TCP. Must-be-fast, loss-tolerant, real-time data → UDP. When you need both (modern web, low-latency-but-reliable), that’s what QUIC-on-UDP is for.
The picture: one lost packet, two outcomes
The cost of each guarantee, in numbers
Here Time is the latency a choice adds and Space is the bytes or state it costs. The RTTs and packet rates are illustrative; the header sizes and handshake counts are the protocols’ own.
| Case | Time | Space | Why |
|---|---|---|---|
| First response, TCP + TLS 1.3 | 3 RTTs: handshake, TLS, then request and reply. 150 ms at a 50 ms RTT, 300 ms at 100 ms | Kernel state per connection: sequence numbers, buffers, timers | TCP and TLS handshake one after the other before the first request can go. |
| First response, QUIC (HTTP/3) | 2 RTTs, or 1 RTT with 0-RTT resumption: 100 ms or 50 ms at a 50 ms RTT | Connection state lives in the app or library, not the kernel | QUIC merges the transport and TLS handshakes into one round trip. |
| First response, a UDP query (DNS) | 1 RTT: 50 ms at a 50 ms RTT | None between queries | Nothing to set up. If the reply never comes, the client times out and asks again. A reply too big for one datagram sets a truncation flag, and the client repeats the query over TCP. |
| Header per packet | Nothing measurable | IPv4 + TCP = 40 bytes; IPv4 + UDP = 28 bytes | A 100-byte game update is 140 bytes over TCP and 128 over UDP. At 50 packets/s the 12-byte gap is 600 B/s, 4.8 kbit/s. |
| Recovering one lost packet | TCP: at least one more RTT before anything behind it is delivered | TCP holds the out-of-order packets in its receive buffer | UDP costs nothing here, because it does not recover the packet at all. |
| Sending under loss | TCP cuts its sending rate when it sees loss, then ramps back up | Nothing extra | Congestion control protects the network and keeps many flows sharing a link fairly. Plain UDP has none, so a UDP app must pace itself or it crowds out everything else on the link. |
| One server, 10,000 clients | Each TCP client pays its own handshake once | TCP: 10,000 connections, each with its own state and buffers. UDP: one socket for all of them | A DNS server answers everyone from one UDP socket. A busy TCP server tunes file-descriptor and memory limits for its connection count. |
| Networks in the way | A blocked UDP path costs a timeout before the fallback | Nothing extra | Some corporate and hotel networks block or throttle UDP. Browsers that try HTTP/3 keep a TCP path (HTTP/2) ready for exactly this. |
| Biggest datagram without fragmentation | Fragmented datagrams arrive only if every fragment does | 1,500 MTU − 20 − 8 = 1,472 bytes of UDP payload | TCP splits a stream into segments itself, so its byte stream never meets this limit. |
Read the table as a bill. TCP charges its latency up front (the handshake) and again on every loss (the stall). UDP charges you nothing, and in return it hands every one of those jobs to your application. That is why “UDP is faster” is only half a sentence. It is faster to start and never stalls, but on a bulk transfer a good TCP stack fills the same pipe, and a UDP app that does not pace itself loses more packets and finishes later.
Common mistakes
- Treating TCP as messages
TCP is a byte stream. Two
send()calls can arrive as oneread(), and one send can arrive split across two reads. Any protocol on TCP needs its own framing, such as a length prefix or a delimiter. With a 4-byte length prefix, the reader first collects 4 bytes, learns the message is, say, 900 bytes long, and keeps reading until it has all 900, however many reads that takes. Code that assumes one send = one read works on localhost and fails under real load. - Reading an ACK as “the server handled it”
A TCP acknowledgement means the peer’s kernel received the bytes. It says nothing about whether the application read them, processed them or crashed straight after. If you need to know the work was done, the application must send its own reply. This is why payment and order APIs pair a response with an idempotency key: a client that never saw the reply can retry safely.
- Rebuilding TCP on UDP by hand
Teams pick UDP for speed, then add acks, ordering and retransmission for every message. Now they have a worse TCP with the same head-of-line stall. Choose per message: resend only what matters (a chat line, a purchase), drop what goes stale (a position update). If you need reliable streams, use QUIC rather than writing your own.
- Sending large UDP datagrams
A datagram bigger than the path MTU is split into IP fragments, and losing any one fragment loses the whole datagram. Some firewalls drop fragments outright. Keep payloads under about 1,472 bytes on a 1,500-byte link, and smaller if tunnels or VPNs sit on the path. On IPv6, routers never fragment, and every link must carry at least 1,280 bytes, so 1,280 − 40 − 8 = 1,232 bytes of payload is safe on any IPv6 path.
- Forgetting UDP has no congestion control
A UDP sender that blasts at a fixed rate keeps blasting when the link fills. It loses more packets and pushes out other traffic. Real-time media stacks measure loss and delay and lower the bitrate themselves; WebRTC, for example, estimates the available bandwidth continuously and steps the video quality down before the link saturates, which is why a call on bad Wi-Fi goes blurry instead of freezing. Also send keepalives: NAT mappings for idle UDP flows expire, and then replies stop arriving.
Which would you pick?
Three situations. Pick the side you'd actually build — the explanation follows.
A live voice call. A packet is lost in transit.
Stale data is worthless here: by the time a lost packet is retransmitted, the moment it belonged to has passed and playing it late corrupts the stream more than dropping it. TCP's guarantee is exactly the wrong thing to buy, and shortening the timeout reduces the wait without removing the head-of-line blocking that causes it.
Downloading a signed release archive over a flaky connection.
Completeness and ordering are the whole requirement, which is what TCP provides for free. Rebuilding acknowledgement, ordering and retransmission on top of UDP is reimplementing TCP with fewer eyes on it, and "faster on lossy links" is meaningless when a single missing byte invalidates the artifact.
You need low latency AND reliability — and someone says you must pick one.
The trade is real at the level of raw TCP versus raw UDP, but it is not the end of the story: QUIC builds reliability and ordering per-stream on top of UDP, avoiding the head-of-line blocking that makes TCP costly under loss. Kernel tuning improves TCP without changing that structural property.
Quick answers
What's the difference between TCP and UDP?
TCP is connection-oriented and reliable: it handshakes, acknowledges and retransmits data, and delivers it in order with flow and congestion control — at the cost of higher latency. UDP is connectionless and best-effort: it fires packets with no guarantees of delivery or ordering and almost no overhead, so it is faster but may lose or reorder data. TCP is for data that must arrive intact; UDP is for data that must arrive fast.
Why is UDP used for video and gaming?
Because for real-time media, late data is worse than lost data. TCP’s in-order guarantee causes head-of-line blocking — a single lost packet stalls everything behind it while it is retransmitted, freezing a live call. UDP simply skips the lost packet and keeps going, so a momentary glitch replaces a freeze. Low latency matters more than completeness, which is exactly UDP’s trade-off.
What is head-of-line blocking?
A delay caused by in-order delivery: because TCP must hand bytes to the application in order, one lost packet blocks all the packets received after it from being delivered until the missing one is retransmitted and arrives. It is fine for files but harmful for live media. QUIC (HTTP/3) was designed to avoid it by multiplexing independent streams over UDP.
Does HTTP/3 use TCP or UDP?
HTTP/3 runs on QUIC, which is built on UDP. QUIC re-implements reliability, ordering and congestion control in user space on top of UDP, giving TCP-grade guarantees while avoiding TCP’s head-of-line blocking and enabling faster connection setup. So modern web transport increasingly uses UDP as the foundation for a reliable protocol, rather than TCP directly.
TCP congestion control: why the internet doesn't melt down
Explore the topic
See this alongside everything else on the same subject — handbooks, system designs, challenges and tools, in one place.
More Handbooks
- The System Design Fundamentals HandbookThe load-bearing ideas behind every distributed system — the CAP theorem and consistency models, concurrency and locking, partitioning and replication, and consensus and coordination — each tied to a real worked design you can study interactively.Read →
- CAP Theorem & Consistency ModelsWhat a distributed system can promise when the network splits — CP vs AP, why "CA" is a myth, PACELC, and the full spectrum from linearizable to eventual consistency. Part of System Design Fundamentals.Read →
- Partitioning, Sharding & ReplicationHow one dataset becomes many — range vs hash partitioning, consistent hashing and virtual nodes, hot partitions, replication topologies, replication lag, and quorums. Part of System Design Fundamentals.Read →
- Consensus, Transactions & CoordinationHow nodes that can crash still agree on one truth — majority quorums, Raft and Paxos, leader election, two-phase commit vs the saga pattern, and idempotency for exactly-once effects. Part of System Design Fundamentals.Read →
- The Kubernetes HandbookThe one idea under all the YAML — declare desired state, and a control loop makes reality match. Covers the orchestration problem, pods, deployments and replicasets, services and networking, the reconciliation loop and self-healing, the scheduler, config/secrets and health probes, autoscaling, and when you actually need Kubernetes.Read →
- The Observability HandbookSeeing inside production — monitoring vs observability, the three pillars (metrics, logs, traces) and what each answers, structured logging, metric types and the cardinality trap, distributed tracing, the golden signals and SLIs/SLOs/error budgets, alerting on symptoms not causes, and correlating all three during an incident.Read →