Unit 2: The Internet · Transporting packets

Article

UDP, the fast way

5 min read

You are on a video call. The picture freezes for a moment, then jumps forward. Your friend's last word is gone. The call does not stop and go back to find it. It just carries on. This is not a bug. It is what a protocol called UDP does on purpose.

UDP: send it and move on

UDP (User Datagram Protocol) is a protocol that sends packets across the Internet with very little extra work. UDP skips three things that many protocols do:

  • It does not set up a connection first. The sender simply starts sending.
  • It does not ask the receiver to confirm that packets arrived.
  • It does not resend packets that are lost, and it does not put packets back in order.

UDP sends and moves on

  1. 1

    Sender → Receiver

    packet 1

  2. 2

    Sender → Receiver✕ lost

    packet 2

  3. Packet 2 never arrives. Nobody asks for it again.
  4. 3

    Sender → Receiver

    packet 3

  5. There are no replies, no checking and no resending.
Every arrow goes one way only. The receiver never answers, so the sender never waits.

UDP still uses IP for addresses and routing. It only decides how much checking to do on top of that, and the answer is: almost none.

So what is the point? Speed. Every check, confirmation and resend costs time. Because UDP skips them, packets leave at once, and nobody waits for anybody. The price is that lost packets stay lost, and packets may arrive out of order.

Check your understanding

Which statement about UDP is true?

When UDP is the right choice

Some data is only useful if it arrives now. A word from a live call is worthless 3 seconds later, because the conversation has moved on. In this kind of use, a short glitch is better than a long pause.

UseWhy UDP fits
Live voice or video callA lost moment of sound is a small glitch. Waiting for it would make the whole call lag.
Online gameThe newest position of a player replaces the old one, so an old lost update does not matter.
Live broadcastViewers want to see what is happening now, not a perfect copy of what happened a while ago.

Check your understanding

Which of these uses is the best match for UDP?

Worked example

An online racing game sends each player's car position 30 times every second. Each update is one small packet.

  1. At second 5, update number 150 is lost on its way.
  2. Update 151 arrives 33 milliseconds later (that is one thirtieth of a second) and shows the car's newer position.
  3. The game ignores the missing update 150. The car may jump a little on screen, but the game keeps running smoothly.

If the game had used a protocol that resends lost packets, update 150 would be sent again. It would arrive late, after 151 and 152 had already shown where the car is now. The old position is useless, and waiting for it could freeze the game. UDP avoids that.

Common mistakes

  • "UDP is a broken or bad protocol." No. It is a good choice when speed matters more than perfect delivery.
  • "UDP never delivers anything." It delivers most packets. It just makes no promise about any single packet.
  • "UDP is faster because it has more bandwidth." No. UDP is faster because it does less work, not because the cable is bigger.
  • "UDP puts packets in order." It does not. The receiver gets packets in the order they arrive.

On the exam

UDP is about speed and low delay, without any guarantee. When a question describes a live service where late data is useless, such as a call or a game, UDP is the likely answer. When every bit of the data must arrive, it is not.

Key words

UDP (User Datagram Protocol): a protocol that sends packets without connecting first, without confirmation and without resending.

Delay: the time it takes for data to arrive.

Glitch: a short, small fault, such as a frozen frame or a missing syllable.

AP® is a trademark registered by the College Board, which is not affiliated with, and does not endorse, this site. All lessons and questions here are written by JrCodex.