The Runtime Theory
easyApplicationFoundations#tcp#udp#transport-protocols

What Is the Difference Between TCP and UDP?

The interview answer covering reliability, ordering, connection state, and when to use each protocol.

TRT practice prompt — not a verified question from a named employer.

The Runtime Theory Team2 min read

What Is the Difference Between TCP and UDP?

Question: What is the difference between TCP and UDP?

Core Answer

Both TCP and UDP are transport-layer protocols — they sit on top of IP and provide communication between applications on different machines. The key difference is:

FeatureTCPUDP
ConnectionConnection-oriented (handshake first)Connectionless (send freely)
ReliabilityGuaranteed delivery, retransmission on lossBest-effort (no retransmission)
OrderingIn-order delivery guaranteedNo ordering guarantee
OverheadHigher (headers, ACKs, buffers)Lower (minimal headers)
Use casesWeb, email, file transferVideo calls, DNS, gaming

TCP: Reliable, Ordered, Connection-Oriented

TCP establishes a connection before sending data, using the famous three-way handshake:

  1. Client sends SYN (synchronize)
  2. Server responds with SYN-ACK (synchronize-acknowledge)
  3. Client sends ACK (acknowledge)

After the handshake, TCP numbers each byte with a sequence number and the receiver acknowledges received data with ACKs. If the sender doesn't receive an ACK within a timeout, it retransmits. If packets arrive out of order, TCP reassembles them in the right order.

This reliability comes at a cost: connection setup latency, per-packet overhead, and head-of-line blocking (if one packet is lost, later packets in the same stream must wait, even if they arrived).

UDP: Fast, Simple, Best-Effort

UDP has no connection setup — the sender just starts sending packets. There is no retransmission, no ordering, no flow control. Each UDP datagram is independent. If a packet is lost, the sender doesn't know and doesn't retry.

This makes UDP ideal for:

  • Real-time media (video calls, live streaming) — a dropped frame is better than a delayed frame
  • DNS — quick request/response, can retransmit at the application layer if needed
  • Gaming — low latency matters more than every packet arriving
  • Broadcast/multicast — sending to many receivers at once

The Trade-off

TCP trades speed for reliability. UDP trades reliability for speed. The choice depends on whether your application can tolerate loss and whether it needs ordering guarantees.

Further Reading

This answer walks

Practice follow-ups

  1. 01When would you choose UDP for a video call over TCP?
  2. 02What is the TCP three-way handshake and why is it necessary?
  3. 03How does TCP handle packet reordering and retransmission?

More interviews in this topic

One dispatch a week

The trace behind each question, the tradeoff that explains it, and one technical dispatch per week — no noise.

One technical dispatch per week. No noise.

Not started

Sign in to save your learning progress.

Sign in to save