← Back to the map

Unit 1 · Lesson 4

TCP vs UDP

A bank transfer must arrive perfectly, even if it takes a moment longer. A video call must arrive now, even if a few pixels are lost. They use different transport protocols for exactly that reason.

By the end you can

Watch

Prefer reading? The same lesson is written out below.

IP moves packets between machines, but it promises nothing: packets can be lost, duplicated or arrive out of order. The transport layer sits on top and decides what to do about that.

TCP: reliable, in orderUDP: fast, may dropBrowserWeb serverGameGame server
Two connections. A browser talks to a web server over TCP, which delivers every byte in order. A game talks to a game server over UDP, which sends independent packets with no delivery guarantee.

TCP: reliable and in order

TCP gives your program a reliable stream of bytes:

Most web traffic, APIs, databases, file transfers and email use TCP, because a missing byte would corrupt the data.

UDP: fast and fire-and-forget

UDP just sends independent packets (datagrams). No handshake, no acknowledgements, no re-sending, no ordering. If a packet is lost, it's gone, unless the application handles it.

That sounds worse, but for live data it's often better. In a video call or an online game, a packet that arrives late is useless: by then you need the next frame. Waiting for a re-send would freeze everything. Better to skip it and carry on.

UDP is used for voice and video calls, live streaming, online games, and DNS lookups (one small question, one small answer; just ask again if it's lost).

Choosing

NeedChoose
Every byte must arrive, in orderTCP
Fresh data matters more than complete dataUDP
Tiny request and answer, easy to retryUDP is fine

A modern twist: QUIC, the protocol under HTTP/3, runs on UDP but adds its own reliability per stream. So one lost packet only stalls the stream it belongs to, not the whole connection.

Key idea: TCP trades a little speed for reliability and order. UDP trades reliability for speed and freshness. Pick based on whether a late packet is still useful.

Check yourself

Which of these does TCP guarantee? (Pick all that apply.)

Your new flashcards

Practice them now. With a free account they come back in your daily review.

Card 1 of 3