Course outline · 0% complete

0/25 lessons0%

Course overview →

UDP vs TCP: choosing your delivery

lesson 3-3 · ~8 min · 8/25

The other option: UDP

TCP's reliability costs time: a handshake before any data, and waiting to retransmit anything lost. UDP (User Datagram Protocol) skips all of it. You address a packet, you send it, done. No handshake, no acks, no retransmission, no ordering. If it gets lost, it is gone.

One term in the table below before you read it: an API (Application Programming Interface) is an HTTP service that programs call to read or change data — when your weather app fetches today's forecast, it is calling the weather company's API. Same request-and-response pattern as a web page, but the answer is data instead of a page. Unit 4 returns to APIs in detail.

TCPUDP
Handshake firstyesno
Lost data resentyesno
Arrives in orderyesno guarantee
Speed overheadsomealmost none
Used byweb pages, APIs, email, file transfervideo calls, live games, DNS lookups

Why would anyone accept lost data? Because for live audio, a packet that arrives late is worse than useless. Nobody wants to hear a word from two seconds ago. Better to drop it and keep going. DNS also uses UDP: the question and answer each fit in one packet, so a whole TCP handshake would triple the cost. If the answer is lost, the resolver just asks again.

Code exercise · bash

Your turn. Classify each application as TCP or UDP with a case statement (like your port classifier in lesson 2-2). The rule you just learned: if every byte must arrive and order matters, TCP; if fresh data beats complete data, or the whole exchange fits in one packet, UDP. Print each app and its transport as shown.

Quiz

You are building a multiplayer racing game that sends each car's position 30 times per second. A stale position is worthless once a newer one exists. TCP or UDP?

Quiz

Loading a bank statement page. TCP or UDP, and why?

Problem

A video call app notices that when a packet of audio is lost, resending it makes conversations feel laggy, because everyone waits for old audio. Which transport protocol should the app use so lost packets are simply skipped? (Three letters.)