Networking for Interviews/Transport Layer: TCP & UDP

TCP Handshake, Reliability & Congestion

Three-way handshake, graceful close vs RST, retransmissions, flow control (receive window), and congestion control at a conceptual level — slow start, loss reaction, head-of-line blocking at the transport layer.

3/5Overview: 25m

Three-way handshake

  1. Client → SYN — proposes connection, initial sequence number.
  2. Server → SYN-ACK — acknowledges, responds with its ISN.
  3. Client → ACK — connection established.

SYN floods are a classic DoS: servers must defend with SYN cookies or rate limits at the edge — know the term, not the kernel implementation.

Teardown that matters in incidents

Graceful close: FIN → ACK → FIN → ACK, with TIME_WAIT on the side that initiated close (waits ~2× MSL for stray packets). High-churn clients can exhaust ephemeral ports in TIME_WAIT.

RST aborts immediately — often means a firewall, LB, or crashed process killed the socket. CLOSE_WAIT pileups mean your app isn't closing sockets after the peer closed — an application bug, not "the network."

Reliability mechanics (verbal depth)

  • Sequence numbers + ACKs — receiver confirms what it got; sender retransmits gaps.
  • Flow control — receive window tells sender how much buffer space remains (receiver-driven).
  • Congestion control — sender backs off when it infers network congestion (packet loss or delay). Classic TCP: slow start → congestion avoidance → fast retransmit on duplicate ACKs.

You don't need to derive the math — explain why a lossy link kills throughput and why bulk transfers behave differently from latency-sensitive RPCs.

Head-of-line blocking at TCP

If segment 2 is lost, segment 3 can't be delivered to the application until 2 is retransmitted — even though 3 arrived. This is transport-layer HOL blocking; HTTP/2 still suffers from it on a single TCP connection (which motivated QUIC).

Senior signal

Connect TCP behavior to symptoms: retransmits → latency spikes; zero window → slow consumer; SYN retransmits → firewall or wrong port; TLS works but HTTP hangs → likely not TCP at all.

Further Reading

Hands-On Tasks (Optional)

Low-setup exercises you can run locally or on a free-tier cloud account. No autograding — the goal is to build intuition, not pass a test.

  • See a TCP handshake with curl -v

    Run `curl -v https://example.com` and identify where DNS, TCP connect, and TLS handshake appear in the output. Optional: capture with Wireshark if you already use it — not required for interview prep.

    15m