System Design AI

TCP vs UDP: Follow-Up Questions Interviewers Ask, With Answers

Interviewers often bring up TCP vs UDP early in a design discussion because the choice of transport layer shapes every other component. They want to see if you understand the basic guarantees, the performance implications, and how those map to real-world traffic patterns.

A follow-up question signals that they expect you to go beyond “TCP is reliable, UDP is fast.” They’ll probe whether you can quantify the trade-offs, anticipate failure modes, and choose the right protocol for the given service level.

Why the Probe Matters

Choosing TCP or UDP isn’t a binary decision; it’s a design lever that affects latency, throughput, scaling, and complexity. A senior engineer must justify the choice in the context of the system’s SLA, while a staff engineer must anticipate edge-case behavior and propose mitigations.

Follow-Up Questions

1. When would you pick UDP over TCP for a new service?

I would pick UDP when the service can tolerate some packet loss but needs latency in the tens of milliseconds, such as real-time gaming or video calls. For example, a 30 fps video call can lose an occasional frame and keep going, whereas the TCP retransmission delay would cause visible stutter. In those cases the latency budget (e.g., < 50 ms end-to-end) outweighs the reliability guarantee.

2. How does TCP’s three-way handshake affect latency?

The three-way handshake adds one round-trip time (RTT) before any data is sent. If the RTT between client and server is 80 ms, the handshake alone costs 80 ms. For short-lived HTTP requests, that overhead can be a significant fraction of total latency, which is why clients reuse connections (HTTP/1.1 keep-alive, HTTP/2 multiplexing many requests over one connection) and why HTTP/3 runs over QUIC, a UDP-based protocol that folds the transport and TLS handshakes into one round trip.

3. What is TCP congestion control and why does it matter?

TCP congestion control throttles the send window based on packet loss or delay signals. The classic algorithm, TCP Reno, halves the congestion window after a loss event. If a flow is sending at 10 Mbps and experiences a loss, the throughput may drop to roughly 5 Mbps until the window grows again. This matters for bandwidth-heavy services because it can cause unpredictable throughput spikes and affect fairness across flows.

4. Can you implement reliability on top of UDP? How?

Yes. You can add sequence numbers, acknowledgments, and retransmission timers in the application layer. For instance, a video conferencing app might send each frame with a sequence ID; the receiver discards duplicates and requests missing frames. This adds overhead—roughly a few bytes per packet—but gives you control over what to retry (e.g., only key frames) and what to drop.

5. How does packet loss affect UDP-based services versus TCP-based ones?

In UDP, loss directly reduces quality; a 1 % loss on a VoIP stream can cause noticeable glitches. In TCP, loss triggers retransmission, so the application sees a delay instead of missing data. For a file transfer, 1 % loss can cut throughput far more than the 1 % of data resent, because each loss shrinks the congestion window (the Mathis model puts loss-limited throughput near MSS / (RTT × √loss)), while a live audio stream would simply sound choppy.

6. What role do MTU and fragmentation play in choosing between TCP and UDP?

If a UDP packet exceeds the path MTU (often around 1500 bytes for Ethernet), the IP layer may fragment it, and any lost fragment forces the whole packet to be discarded. TCP handles fragmentation internally and can retransmit only the missing segment. Therefore, for large payloads—say a 4 KB JSON message—TCP is safer, while UDP is best for small, fixed-size packets like sensor readings (< 512 bytes).

7. How do you handle ordering guarantees when using UDP?

I would embed a monotonically increasing sequence number in each UDP packet. The receiver buffers out-of-order packets and delivers them to the application only when all prior packets have arrived, or after a timeout. For example, a telemetry system might tolerate a 100 ms reordering window, after which missing data is dropped.

8. What are the security implications of choosing UDP over TCP?

UDP is more susceptible to spoofing because there is no handshake to verify the source. An attacker can flood a UDP service with forged packets, or spoof a victim’s address so that the service’s larger replies flood the victim (an amplification attack), so a UDP service should limit what it sends to an address it has not verified (QUIC caps it at three times the bytes received). To mitigate this, I would place the service behind a firewall that only allows traffic from known IP ranges and use DTLS to provide authentication and encryption at the UDP layer.

9. How would you design a fallback from UDP to TCP for a critical service?

I would start with UDP for the primary data path and monitor packet loss and latency. If loss exceeds a threshold—say 2 % over a 10-second window—I would switch the client to a TCP fallback channel, re-establishing a connection and resuming the stream. This dual-transport approach gives the low-latency benefits of UDP while guaranteeing delivery when network conditions degrade.

Senior vs. Staff Answers

A senior-level answer explains the trade-offs, cites concrete numbers, and ties the protocol choice to the service’s SLA. A staff-level answer goes further: it anticipates rare failure modes (e.g., silent packet loss due to MTU fragmentation), proposes monitoring and automated fallback strategies, and discusses security hardening. Staff engineers also consider operational impacts—like how the choice affects load balancer configuration or observability tooling.

How to practice this

  1. Sketch a simple diagram of a client-server interaction, label the transport layer, and note the latency and reliability requirements.
  2. Write out the nine questions and rehearse answering each in the first person, using real numbers from your own projects.
  3. With System Design AI Pro ($10/month), draw the full answer flow on the practice canvas, then mark where you can add concrete metrics.

Questions people ask

When is it okay to ignore TCP’s congestion control?

Almost never. Even in a private data-center network, flows compete for switch buffers, so you keep congestion control on and choose an algorithm tuned for that environment, such as DCTCP, rather than turning it off.

Does UDP guarantee ordering?

No. UDP delivers each datagram independently. If ordering matters, you must add sequence numbers and reordering logic in the application layer.

Can TCP be used for low-latency gaming?

It can, but one lost packet stalls every later packet on the connection until it is retransmitted (head-of-line blocking), which is too much delay for fast-paced games; the handshake is paid only once per connection. Many games use TCP for login or matchmaking and switch to UDP for the real-time gameplay stream.

How does NAT affect UDP traffic?

NAT creates a temporary mapping for each outbound UDP flow. If the mapping expires, inbound packets are dropped, causing silent loss. Sending periodic keep-alive packets keeps the mapping alive.