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 live video streaming. For example, a 30 fps video stream can drop a few frames per second and still look smooth, 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 protocols like HTTP/2 use connection pooling or why some services prefer UDP-based protocols to avoid the initial delay.

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, a 1 % loss might increase total transfer time by 10 % due to retransmission, 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, leading to amplification attacks. 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-stack 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. Use System Design AI’s canvas to draw the full answer flow, then ask the AI coach to review your explanation and suggest 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. The risk of congestion collapse is low because you manage the traffic patterns.

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 the three-way handshake and retransmission delay often add too much latency for fast-paced games. 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.