Vibe Engines
YouTube

Vibe Engines is free, interactive AI engineering & system design — runs in your browser. Pick a learning path

Handbooks  /  TCP vs UDP
Engineering~9 min readComparison
Head to Head

TCP vs UDP: guaranteed delivery, or raw speed?

TCPvsUDP

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.

01

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.

→ The rule

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.

02

Head to head

DimensionTCPUDP
ConnectionHandshake, stateful connectionConnectionless — just send
ReliabilityGuaranteed — ACKs + retransmitNone — packets may vanish
OrderingIn-order delivery guaranteedNo ordering — may arrive shuffled
Flow / congestion controlYes — adapts to receiver & networkNo — sends as fast as you ask
Header overheadLarger (20+ bytes, more state)Tiny (8 bytes)
LatencyHigher — handshake, ACKs, retransmit waitsLower — no waiting on delivery
On packet lossStalls to retransmit (head-of-line blocking)Drops it and keeps going
Typical useHTTP, email, file transfer, DB connectionsVideo/voice, gaming, DNS, streaming
03

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
04

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.

→ The cheap default

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.

05

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

→ The trade you’re actually making

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.

06

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.

→ The pattern generalizes

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

The picture: one lost packet, two outcomes

on the wirewhat the app gets TCPUDP 1 2 3 4 5 gets 1, 2 4, 5 heldwaiting for 3 resend costs ≥ 1 RTT, then 3, 4, 5 1 2 3 4 5 gets 1, 2, 4, 5 3 skipped a glitch, not a stall 3 lost3 lost time →
Same loss, opposite reactions. TCP has 4 and 5 in hand but may not pass them up out of order, so the app waits a full round trip or more for the resend of 3. UDP passes up whatever arrives and leaves the gap to the app, which can conceal it (repeat the last audio frame, interpolate a position) or ignore it. QUIC sits between the two: it does resend 3, but only the stream that 3 belongs to waits for it. Other streams on the same connection, say an image loading beside a script, keep flowing.
Trade-offs

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.

CaseTimeSpaceWhy
First response, TCP + TLS 1.33 RTTs: handshake, TLS, then request and reply. 150 ms at a 50 ms RTT, 300 ms at 100 msKernel state per connection: sequence numbers, buffers, timersTCP 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 RTTConnection state lives in the app or library, not the kernelQUIC merges the transport and TLS handshakes into one round trip.
First response, a UDP query (DNS)1 RTT: 50 ms at a 50 ms RTTNone between queriesNothing 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 packetNothing measurableIPv4 + TCP = 40 bytes; IPv4 + UDP = 28 bytesA 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 packetTCP: at least one more RTT before anything behind it is deliveredTCP holds the out-of-order packets in its receive bufferUDP costs nothing here, because it does not recover the packet at all.
Sending under lossTCP cuts its sending rate when it sees loss, then ramps back upNothing extraCongestion 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 clientsEach TCP client pays its own handshake onceTCP: 10,000 connections, each with its own state and buffers. UDP: one socket for all of themA 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 wayA blocked UDP path costs a timeout before the fallbackNothing extraSome 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 fragmentationFragmented datagrams arrive only if every fragment does1,500 MTU − 20 − 8 = 1,472 bytes of UDP payloadTCP 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.

Watch for

Common mistakes

  • Treating TCP as messages

    TCP is a byte stream. Two send() calls can arrive as one read(), 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.

Your call

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.

Downloading a signed release archive over a flaky connection.

You need low latency AND reliability — and someone says you must pick one.

Frequently asked

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.

▶  Watch it explained

TCP congestion control: why the internet doesn't melt down

TCP vs UDP · Vibe Engines · 2026
Finished this one? 0 / 209 Handbooks done
NextThe API Design Handbook Next on the “Networks, APIs and auth” ladder · rung 3 of 9

Explore the topic

See this alongside everything else on the same subject — handbooks, system designs, challenges and tools, in one place.

More Handbooks