KatInterview

TCP vs UDP Trade-offs and How TCP Infers Packet Loss

System DesignModel answer
MediumModel answerSystem Designnetworkingtcpudp

Last updated

Compare TCP and UDP across reliability, ordering, congestion control, setup and overhead, then explain how TCP detects loss through timers, duplicate ACKs and SACK.

You are designing a networked service and need to justify your choice of transport protocol.

Part 1. Compare TCP and UDP along these axes:

  • reliability
  • ordering
  • congestion and flow control
  • connection setup and teardown
  • per-packet overhead

Say when you would pick each one.

Part 2. The network never tells a TCP sender that a packet was dropped. Explain how the sender infers loss and decides to retransmit. Cover at least:

  • retransmission timeouts
  • duplicate ACKs and fast retransmit
  • selective acknowledgments (SACK)

Also discuss how the sender's behavior differs between these signals, and which edge cases make loss detection hard.

A strong answer is structured, gives concrete numbers or formulas where they help, and names trade-offs. You may include a short code sketch of the sender-side logic.

Hints

Hint 1

Think of TCP as a reliable ordered byte stream built on an unreliable packet network, and UDP as little more than IP plus ports and a checksum. Ask which responsibilities each pushes onto the application.

Hint 2

The sender has two kinds of evidence for loss: silence (a timer expires with no ACK) and ACK patterns (repeated cumulative ACKs, or SACK blocks showing gaps). Ask which is faster and which is more reliable.

Hint 3

Consider cases where the faster signals fail: very small windows, loss of the last packets in a flight, reordering that looks like loss, and retransmitted segments whose ACKs are ambiguous for RTT measurement.