Interview questions and model answers
"TCP vs UDP — when would you pick UDP?"
TCP gives reliable, ordered, congestion-controlled byte streams with a handshake; UDP is connectionless, message-based, with no delivery guarantees but minimal overhead. I'd pick UDP when timeliness beats completeness — voice, video, gaming — for tiny request/response protocols like DNS and NTP where retrying is cheaper than a handshake, for high-volume telemetry where occasional loss is fine, or when building a custom transport like QUIC that adds exactly the reliability it needs.
"How does TCP guarantee delivery?"
Every byte has a sequence number and the receiver sends cumulative acknowledgements. If an ACK doesn't arrive within the retransmission timeout, or three duplicate ACKs signal a gap, the sender retransmits — with SACK so only missing segments are resent. The receiver reorders data by sequence number, and checksums catch corruption. Flow control via the receive window and congestion control via the congestion window keep the sender from overwhelming the receiver or the network.
"Why does 1% packet loss hurt TCP throughput so much?"
Congestion control interprets loss as congestion and cuts the congestion window — by roughly half with Reno, about 30% with CUBIC — then grows it back slowly, about one segment per round trip. On high-latency paths recovery takes many RTTs, so frequent losses keep the window small, and throughput is bounded by window over RTT. Timeouts are even worse because the window collapses entirely. BBR handles lossy paths better because it models bandwidth instead of reacting to each loss.
"Why does DNS use both UDP and TCP?"
Normal queries are small, so UDP avoids a handshake and the client just retries on timeout. When a response is too large — DNSSEC, many records — the server sets the truncated flag and the client retries over TCP; zone transfers always use TCP. So security groups and firewalls must allow both UDP and TCP 53, otherwise you get intermittent failures on large responses.
"Why did HTTP/3 move to UDP?"
TCP's in-order delivery causes head-of-line blocking — one lost packet stalls every multiplexed HTTP/2 stream — and TCP plus TLS needs multiple round trips to start. Changing TCP is nearly impossible because it's in kernels and middleboxes everywhere. QUIC builds streams, reliability, congestion control and TLS 1.3 on UDP in user space: independent streams, 1-RTT or 0-RTT setup, and connection migration across networks.
"Pods see random 5-second delays on outbound calls. What's going on?"
Classic DNS conntrack race: glibc sends A and AAAA queries in parallel over UDP from the same socket, conntrack drops one under a race, and the resolver waits five seconds to retry. I'd confirm by timing DNS lookups from a pod and checking conntrack insert-failed counters, then deploy NodeLocal DNSCache or set single-request-reopen in dnsConfig, and reduce ndots-driven extra lookups.
"How do you load balance a UDP service on AWS?"
With a Network Load Balancer using a UDP or TCP_UDP listener and a target group on that port. Health checks must use TCP or HTTP because UDP has no handshake, so the service needs a TCP or HTTP health endpoint. Security groups need UDP rules for clients and the health-check port for the NLB.