LearnThatStack Ace your next interview
Networking for Developers · question
Question 3 of 51

What is the difference between TCP and UDP, and when do you use each?

beginner
← All Networking for Developers questions
Re-explain

TCP gives you a reliable, ordered stream, while UDP gives you fast, best-effort messages. TCP sets up a connection, tracks every byte and resends lost data. It delivers bytes in order, so what you send arrives whole.

UDP just fires packets with no handshake and no retries. Packets can arrive late, out of order, or not at all. In exchange it has almost no overhead and lower latency.

Reach for TCP when correctness matters, as in web pages and APIs. File transfers and databases need it too. Reach for UDP when speed beats completeness, as in live video and voice calls. Games and DNS lookups use it for the same reason. Losing one frame of video beats stalling the whole stream.

Rewriting in plainer words…

This answer doesn't lend itself to a diagram - it reads best . No credits were charged.

Why there's no diagram: “”

The interactive diagram is below the answer - jump to diagram ↓ · Below it, the related concept . Jump to it ↓

The diagram below the answer is the concept . Jump to it ↓

Tailored explanation · switch back to · ·
What should the new diagram focus on?
Guided practice for Networking for Developers One question at a time. Answer out loud, get graded, see what you missed.
How well did you know this?
AI:

Saved in this browser - sign in to keep your review list.

How should your speech become text?

Listening… your words appear above as you speak - tap Stop when you're done.

Recording · cr - tap Stop & transcribe when you're done.

Transcribing with AI…

Voice:

Keep going - a few more words and AI can grade it.

Interview lens How interviewers actually use this question

Likely follow-ups

  • If you build on UDP, what does your application now have to handle itself? Expect loss, reordering and duplicates. Add sequence numbers and timeouts where needed, and pace sends, since UDP has no congestion control.
  • How does TCP make sure nothing is lost and bytes arrive in order? Name sequence numbers, acknowledgments, retransmission after a timeout, and the receiver holding out-of-order data until the gap is filled.
  • DNS lookups usually go over UDP. When does DNS switch to TCP? Small query, small reply, no handshake. Then TCP when a response is truncated because it is too big for UDP, and for zone transfers.
  • HTTP/3 runs over UDP. Why not stay on TCP? With TCP, one lost packet stalls every stream on the connection. QUIC builds reliability per stream on UDP, so a loss stalls only its own stream.
  • For a multiplayer game, which traffic would you send over UDP and which needs reliability? Position updates go over UDP because the next update replaces a lost one. Chat, purchases and login must arrive, so they need TCP or a reliable layer.

What you can say

  1. TCP gives you a reliable, ordered byte stream, and UDP gives you fast, best-effort messages with no guarantees.
  2. TCP sets up a connection first, tracks every byte and resends anything lost, then delivers bytes in order, so what you send arrives whole.
  3. UDP just fires packets with no handshake and no retries, so they can arrive late, out of order, or not at all, but it has almost no overhead and lower latency.
  4. So I reach for TCP when correctness matters, like web pages, APIs, file transfers and databases, and UDP for live video, voice calls, games and DNS lookups.
  5. With live video, losing one frame beats stalling the whole stream, but if every byte has to arrive, UDP is the wrong choice.

Weak answers to avoid

  • Treats UDP as the broken, unreliable one UDP drops guarantees on purpose to cut latency. Say when that wins, like a voice call where a late packet is useless and a resend would only add delay.
  • Lists properties, never says when to use each The question asks when. Tie each protocol to real traffic and the reason, such as APIs needing every byte and live video needing low delay.
  • Says TCP is secure or encrypted TCP guarantees delivery and order, not privacy. Encryption comes from TLS running on top of it, so keep reliability and security separate.
Interview lens

Likely follow-ups, what you can say, and the weak answers to avoid.

Sign in free to open it Free account - the lens opens as soon as you're back.

Want a quick review of the fundamentals? See the Networking for Developers cheatsheet.

← Back to all Networking for Developers questions
Pro · $10/mo

44 of 51 Networking for Developers answers are in Pro.

Full answers, code samples, and AI explanations that go simpler or deeper. Cancel anytime.

  • Full answers + code
  • AI explanations, simpler or deeper
  • 1,000 AI credits / month
  • Cancel anytime