When an interviewer asks about TCP versus UDP, they’re not just testing terminology—they want to see whether you can map protocol characteristics to real‑world constraints. Below is a set of questions you might encounter, from entry‑level to senior, each paired with a short spoken answer (45‑90 seconds) and a typical follow‑up. Practice the answers out loud; tools like Call Assistant can capture your phrasing and suggest tighter wording while keeping the conversation on track.

1. Basic Definitions

What is TCP and what is UDP?

TCP (Transmission Control Protocol) is a connection‑oriented, reliable transport layer protocol. It guarantees that bytes arrive in order, without loss, and it provides flow and congestion control. UDP (User Datagram Protocol) is connection‑less and best‑effort: it sends datagrams without establishing a session, offers no delivery guarantee, and incurs minimal overhead.

Typical follow‑up: Why would you ever choose UDP if TCP is more reliable?

Sample answer

"TCP builds a virtual circuit with a three‑way handshake, tracks each segment, and retransmits lost packets. UDP just stamps a header onto a payload and hands it to IP. The trade‑off is latency versus reliability. In my last project, I used TCP for file transfers because we needed every byte, but switched to UDP for live sensor streams where a few dropped packets were acceptable.",

2. Handshake and Connection Management

How does TCP’s three‑way handshake work?

  1. SYN – client sends a segment with the SYN flag set and an initial sequence number.
  2. SYN‑ACK – server acknowledges the client’s SYN and responds with its own SYN and sequence number.
  3. ACK – client acknowledges the server’s SYN. After this exchange, both sides have agreed on initial sequence numbers and can exchange data.

Typical follow‑up: What happens if the third ACK is lost?

Sample answer

"If the final ACK never arrives, the server will timeout and retransmit its SYN‑ACK. The client, upon receiving the duplicate, will resend the ACK. This retry loop continues until the connection is either established or aborted, ensuring reliability.",

3. Reliability Mechanisms

How does TCP guarantee ordered delivery?

TCP assigns a sequence number to each byte. The receiver buffers out‑of‑order segments and acknowledges the highest contiguous byte received. Missing segments trigger retransmission after a timeout or duplicate ACK detection (fast retransmit). This mechanism ensures the application sees data in the exact order it was sent.

Typical follow‑up: Explain fast retransmit and fast recovery.

Sample answer

"When the sender receives three duplicate ACKs, it assumes a segment is lost and retransmits it immediately—this is fast retransmit. Fast recovery then reduces the congestion window only partially, allowing the connection to keep sending while avoiding a full slow‑start.",

4. Congestion Control

What are the main phases of TCP congestion control?

  • Slow Start: window grows exponentially until loss is detected.
  • Congestion Avoidance: window grows linearly, probing for available bandwidth.
  • Fast Retransmit/Recovery: reacts to packet loss without resetting to slow start.
  • Timeout: severe loss triggers a return to slow start.

Typical follow‑up: How would you tune these phases for a high‑latency data center link?

Sample answer

"In a high‑latency environment I’d increase the initial congestion window and use TCP‑BIC or TCP‑CUBIC, which are designed for long‑fat networks. The goal is to fill the pipe faster while still backing off when loss occurs.",

5. UDP Characteristics

What are the advantages of UDP?

  • Minimal header (8 bytes) → lower per‑packet overhead.
  • No connection setup → faster start‑up.
  • No retransmission or flow control → predictable latency.
  • Supports broadcast and multicast natively.

Typical follow‑up: What are the security implications of using UDP?

Sample answer

"Because UDP lacks built‑in checksums beyond a simple optional one, it’s vulnerable to spoofed packets and amplification attacks. In production we mitigate this by placing UDP services behind firewalls, validating payloads at the application layer, and, where possible, using DTLS for encryption.",

6. Use‑Case Matching

When would you use TCP vs UDP in a microservice architecture?

  • TCP for RPC, database queries, or any operation where correctness outweighs latency.
  • UDP for telemetry, video streaming, or service discovery where occasional loss is tolerable and low latency is critical.

Typical follow‑up: Give an example of a hybrid approach.

Sample answer

"In a recent system we built a real‑time dashboard. Sensors pushed metrics via UDP to a collector; the collector then used TCP to persist the data in a time‑series database. This kept the ingest path fast while guaranteeing durability for analytics.",

7. Performance Considerations

How does MTU affect TCP and UDP performance?

Both protocols inherit the IP MTU limit. For TCP, large segments are split into multiple packets; loss of any segment forces retransmission of the whole window, hurting throughput. UDP can send larger datagrams, but if they exceed the MTU they are fragmented; a single lost fragment discards the whole datagram. Hence, keeping payloads below the typical MTU (≈1500 bytes on Ethernet) is advisable for both.

Typical follow‑up: What techniques can you use to avoid fragmentation?

Sample answer

"I usually set the UDP payload size to 1 200 bytes and enable Path MTU Discovery for TCP, which automatically adjusts the segment size based on the smallest MTU along the route.",

8. Real‑World Debugging

How would you troubleshoot a flaky UDP‑based video stream?

  1. Capture traffic with tcpdump or Wireshark to verify packet loss and ordering.
  2. Check for NAT or firewall timeouts that may drop idle UDP flows.
  3. Measure round‑trip latency; high jitter often points to congestion.
  4. Adjust application‑level buffering or switch to a more resilient codec.

Typical follow‑up: What metrics would you monitor?

Sample answer

"I’d monitor packet loss rate, jitter, and end‑to‑end latency. If loss exceeds a few percent, I’d look at QoS policies and possibly fallback to a TCP‑based stream for critical moments.",

9. Advanced Topics

Explain UDP‑based protocols that add reliability (e.g., QUIC, RTP).

  • QUIC runs over UDP but implements its own stream multiplexing, congestion control, and encryption, offering lower latency than TCP while preserving reliability.
  • RTP (Real‑time Transport Protocol) adds sequencing and timestamping to UDP, allowing receivers to reorder packets and compensate for jitter.

Typical follow‑up: Why might a team still choose raw UDP over QUIC?

Sample answer

"Raw UDP removes the overhead of connection management and cryptographic handshakes, which can be important for ultra‑low‑latency scenarios like high‑frequency trading where even a few milliseconds matter.",

10. Relating to Your Experience

How do you decide which protocol to use in a new project?

Start by listing functional requirements: reliability, ordering, latency, bandwidth, and network topology. Map each requirement to protocol traits. If you need guaranteed delivery, pick TCP. If you need sub‑second latency and can tolerate loss, pick UDP or a UDP‑based protocol with optional reliability.

Typical follow‑up: Can you walk me through a decision you made?

Sample answer

"In my last role we built a remote‑control system for drones. Commands were sent via UDP because we needed <10 ms latency; the drone acknowledged critical commands over TCP to ensure they weren’t missed. This split‑path architecture let us keep control responsive while still guaranteeing safety‑critical actions.",


How to practice this

  1. Record yourself answering each question in 45‑90 seconds. Replay the audio and trim any filler words.
  2. Simulate follow‑ups by having a colleague ask the next question. Use Call Assistant to capture the exchange and highlight where you drifted off topic.
  3. Map each answer to a concrete project on your résumé. Replace generic statements with specific metrics or outcomes you can discuss confidently.

FAQ

  • Q: Is UDP faster than TCP in every scenario? A: Not always. UDP avoids connection overhead, but if the network is lossy, retransmissions at the application layer can negate the latency benefit. TCP’s congestion control can actually keep throughput higher on congested links.
  • Q: Can TCP guarantee zero packet loss? A: TCP guarantees that the data delivered to the application is complete and ordered, but it cannot prevent loss on the wire; it compensates by retransmitting lost segments.
  • Q: When is it safe to ignore packet loss in a UDP service? A: When the application tolerates occasional missing data—e.g., live video, telemetry, or gaming—where stale data is less useful than a brief pause.
  • Q: How do firewalls treat UDP differently from TCP? A: Many firewalls track UDP flows using timeouts rather than explicit connection states, so idle UDP traffic may be dropped sooner. This requires explicit keep‑alive packets or NAT traversal techniques.

Frequently asked questions

Is UDP faster than TCP in every scenario?

Not always. UDP avoids connection overhead, but if the network is lossy, retransmissions at the application layer can negate the latency benefit. TCP’s congestion control can actually keep throughput higher on congested links.

Can TCP guarantee zero packet loss?

TCP guarantees that the data delivered to the application is complete and ordered, but it cannot prevent loss on the wire; it compensates by retransmitting lost segments.

When is it safe to ignore packet loss in a UDP service?

When the application tolerates occasional missing data—e.g., live video, telemetry, or gaming—where stale data is less useful than a brief pause.

How do firewalls treat UDP differently from TCP?

Many firewalls track UDP flows using timeouts rather than explicit connection states, so idle UDP traffic may be dropped sooner. This requires explicit keep‑alive packets or NAT traversal techniques.

#concept questions#TCP vs UDP#network protocols#interview prep#systems design