OS, networking and concurrency · Question 31 of 50

What is the difference between TCP and UDP?

What they're checking

Reliability trade-offs, with real examples.

The answer

TCP opens a connection with a handshake and delivers everything, in order: lost packets are sent again, the receiver acknowledges, and flow and congestion control pace the sender. That costs latency, and one lost packet holds up everything behind it (head-of-line blocking).

UDP just sends datagrams: no connection, no ordering, no retries, very little overhead. TCP for web pages, APIs, file transfers and email; UDP for video calls, games and DNS lookups, where late data is useless anyway. HTTP/3 runs on QUIC, which builds reliability on top of UDP to avoid TCP's head-of-line blocking.

The picture

TCP:  SYN ▶   ◀ SYN-ACK   ACK ▶   data 1 2 3   (2 lost → sent again)  ✓ in order
UDP:  data 1 ▶   data 2 ▶   (3 lost)   data 4 ▶   no handshake, no resend
The follow-up they'll ask

Why does DNS use UDP?

Show the answer

One small question, one small answer: a handshake would double the time. It falls back to TCP for large answers.

Your progress stays on this device.