Katkat

TCP vs UDP: Key Differences and the Applications That Suit Each

ByteDanceSoftware Engineer · Technical Screen

Last updated

From a TikTok backend intern interview: compare TCP and UDP, including connection setup, reliability, ordering, flow and congestion control, message boundaries and overhead, and explain which applications suit each protocol. It tests tying transport-layer guarantees and their costs to real application needs.

Compare TCP and UDP. Explain how the two transport protocols differ, and for each one, describe the application scenarios where it is the right choice and why.

Clarifying Questions

  • Should the comparison stay at the transport layer, or also cover protocols built on top of UDP that add their own reliability?
  • Is there a specific workload in mind, such as the e-commerce backend services this team builds, or is a general comparison wanted?

Hints

Hint 1

Go beyond reliable versus unreliable: List what TCP actually guarantees (connection setup, ordering, retransmission, flow and congestion control), what each guarantee costs in latency or overhead, and which applications would rather not pay that cost.

Follow-up questions

  • Why does DNS normally use UDP, and when does it fall back to TCP?
  • What is head-of-line blocking in TCP, and how does QUIC avoid it while running over UDP?
  • What is the TIME_WAIT state, and why can a client that opens many short-lived TCP connections run into trouble?
  • TCP delivers a byte stream. How does an application on top of it know where one message ends and the next begins?