AI Hints
Home›System Design Tutorial›How the Network Works
System Design · Lesson 15 of 120

TCP vs UDP

Reliable or fast.

⏱ 2 min read▶ Video at 16:45🎓 Free
Watch this lesson in the System Design courseWatch on YouTube ↗Full System Design course

Under HTTP, data is broken into small packets. Two protocols carry them. TCP makes sure every packet arrives, in order. UDP just sends them, and hopes for the best.

TCP vs UDP
From the video: TCP vs UDP
  • Data in small packets
  • TCP: every packet, in order
  • UDP: send and hope

Two protocols

TCP starts with a handshake, numbers every packet, and resends anything that's lost. That makes it reliable, but a little slower. UDP skips all of that. It's faster, with less delay, but packets can be lost or arrive out of order. The application has to cope.

TCP: reliable

  • Handshake firstResends lost packetsWeb, email, files

UDP: fast

  • No handshakeLost is lostVideo calls, games, DNS

Choosing one

When should you use which? If every byte matters, like a web page, a payment, or a file, use TCP. If speed matters more than perfection, like a live video call, use UDP. A missing video frame is better than a frozen call. Newer protocols, like HTTP three, build reliability on top of UDP.

Every byte mattersTCP
Live and fastUDP
Video calls, gamesUDP
HTTP/3reliable on top of UDP

Summary

TCP is reliable and ordered, UDP is fast and loose. Most web traffic uses TCP. Next, the most common way to design an API. REST.

Key takeaways
  • TCP: reliable, ordered
  • UDP: fast, lossy
  • Pick by what matters
Next up: REST APIs — resources and verbs