KatInterview

Choosing Between TCP and UDP for Different Network Workloads

System DesignModel answer
MediumModel answerSystem Designnetworkingtcpudp

Last updated

Contrast TCP and UDP on connection handling, reliability, ordering, flow and congestion control, framing and overhead, then match each to workloads where its guarantees fit.

You are designing the networking layer of several services and must decide which transport protocol each one should use.

Compare TCP and UDP:

  1. Explain how they differ in connection setup, delivery guarantees, ordering, flow and congestion control, message framing, and per-packet overhead.
  2. For each protocol, describe workloads where it is the better choice and name the specific property that decides it.
  3. Explain how an application can obtain some reliability on top of UDP, and when that is worth doing.

A good answer links each protocol feature to its cost (latency, bandwidth, complexity) rather than only listing differences. You may assume a general-purpose backend context, such as an online store with APIs, payments, live video support chat, and telemetry.

Hints

Hint 1

Start from what each protocol promises to the application: a reliable ordered byte stream versus best-effort independent datagrams. Then ask what each promise costs.

Hint 2

Think about what happens when one packet is lost. For TCP, later data must wait (head-of-line blocking). For real-time audio or game state, is old data still useful when it finally arrives?

Hint 3

Do not forget message boundaries: TCP is a stream, so the application must frame messages, while each UDP datagram is delivered as a unit or not at all. Also consider protocols such as QUIC that rebuild reliability over UDP.