Networking interview question · Most asked
What's the difference between TCP and UDP, and when would you choose UDP?
Summary
TCP provides a reliable, ordered byte stream with connection setup, retransmission, flow and congestion control. UDP sends independent datagrams with no handshake or delivery guarantees. Choose UDP for small request/response exchanges (DNS), real-time media where late data is useless, or when a protocol implements its own reliability (QUIC).
Longer Answer
UDP's 8-byte header and lack of state make it cheap, but firewalls and NAT must track UDP flows by timeouts, and many networks block it. QUIC (under HTTP/3) runs over UDP to get independent streams, faster connection setup and connection migration, while implementing reliability and encryption itself.
Key Points
- TCP: reliable, ordered, connection-oriented.
- UDP: datagrams, no guarantees, no handshake.
- UDP for DNS, media, games, QUIC.
- UDP is often blocked or rate-limited on corporate networks.
Deep dive: Networking Tutorial: UDP
Explanation
What interviewers look for
Trade-offs, with real examples, including QUIC.
More most-asked Networking questions
- What happens, at the network level, when you type a URL into a browser and press Enter?
- What's the difference between stateful and stateless firewalls? Give cloud examples.
- What is CIDR notation? How many usable addresses are in a /26, and in an AWS /26 subnet?
- How does DNS resolution work, and what does a record's TTL control?
- What does TLS provide, and how does certificate validation work?
- How does NAT work, and what are its limits?
- What do 502, 503 and 504 errors from a load balancer usually mean?
- A service is unreachable. How do you troubleshoot it systematically?