Why do DNS, DHCP and NTP run over UDP rather than TCP, and what does each gain from that choice?
answer
- small request, small response
- cost of a round trip
- a host with no address yet
- stale timestamps are useless
basics
~20 sDNS, DHCP and NTP exchange small, self-contained requests and responses, so a TCP handshake would add a round trip and server state for little benefit. DHCP must also broadcast, which TCP cannot, and NTP prefers a fresh sample to a delayed one.
solid answer
~40 sAll three are tiny, self-contained request/response exchanges where the client can just ask again. For DNS, UDP means one round trip instead of two, and a busy server keeps no per-client connection state; RFC 1035 has the client retransmit lost queries. DNS still uses TCP for truncated responses and zone transfers, and RFC 7766 requires every general-purpose implementation to support TCP. DHCP runs on UDP because the client has no IP address yet and must broadcast, and TCP supports only unicast connections. NTP computes clock offset from send and receive timestamps, so a reply delayed by retransmission is a worse sample than simply polling again.
go deeper
Remember the pattern: one small question, one small answer, and the client can retry. Know that DNS also uses TCP for large responses.
Explain the round-trip arithmetic for DNS, the broadcast requirement for DHCP, and why a delayed NTP sample is worse than a new one.
Be ready to discuss RFC 7766's change that makes TCP a normal DNS transport, and what per-client connection state would cost a busy resolver or authoritative server.
Weigh when an organisation should move lookups to connection-based transports anyway, trading latency and server state against response size limits and operational needs.
## The shape these three protocols share DNS lookups, DHCP address assignment and NTP time synchronisation have one thing in common: they are built from **small, self-contained requests and responses**. Each question fits in one datagram, each answer usually fits in one datagram, and if either is lost the client can simply ask again. For that shape, TCP's machinery costs more than it returns: - a **handshake** round trip before the question can be delivered, - **per-connection state** (a Transmission Control Block) on the server for every client, - a **teardown** exchange afterwards, - retransmission and in-order delivery that the application can provide more cheaply for a single message. ## DNS: one question, one answer, a server with many clients Over UDP, a lookup costs one round trip: query out, response back. Over a fresh TCP connection it costs two: the handshake, then the query and response. RFC 7766 names the penalty directly as "the added connection setup latency, generally equal to one RTT". A busy recursive or authoritative server also avoids holding connection state for every client it answers. Reliability is rebuilt in a few lines of client logic. RFC 1035 section 4.2.1 says that UDP queries "may be lost, and hence a retransmission strategy is required", and recommends trying other servers or addresses before repeating a query to the same one. DNS is **not UDP-only**, and saying so is part of a good answer: 1. RFC 1035 limits a DNS message carried over UDP to 512 bytes, not counting the IP and UDP headers. A longer response is truncated and the `TC` bit is set, and the client can retry over TCP. (The truncation and size-extension mechanics belong to the DNS transport topics.) 2. Zone transfers use TCP: RFC 1035 says "UDP is not acceptable for zone transfers". 3. RFC 7766 requires all general-purpose DNS implementations to support **both** UDP and TCP, relaxes RFC 1123's rule that a UDP query must be sent first, and says TCP "ought to be considered a valid alternative transport to UDP, not purely a retry option". ## DHCP: the client has no address yet A host joining a network has no IP address configured and does not know where the DHCP server is, so it has to **broadcast**. TCP cannot do that. RFC 9293 states that "TCP supports unicast delivery of data", and a SYN addressed to a broadcast or multicast address is ignored. A TCP connection is also identified by an address and port at each end, and the client does not yet have an address of its own. UDP carries broadcast and multicast traffic; RFC 8085 section 4 notes that multicast and broadcast transmission usually employ UDP. The DHCP message sequence itself belongs to the DHCP topic. ## NTP: a late sample is a bad sample NTP estimates the offset between a client's clock and a server's from timestamps taken as the request leaves and arrives and as the reply leaves and arrives. The estimate is only as good as the assumption that the network delay was about the same in both directions. A reply held back by a TCP retransmission, or queued behind a lost segment, carries timing that is stale and lopsided. Discarding that exchange and taking the next sample is better than recovering it. NTP's own filtering algorithms belong to the NTP topic; the transport lesson is that **timeliness beats completeness** here. ## Side by side | Protocol | Main reason for UDP | What the application rebuilds itself | |---|---|---| | DNS | One round trip instead of two; no per-client connection state on the server | Timeouts, retransmission, trying another server | | DHCP | The client has no address and must broadcast | Retransmitting its own requests | | NTP | A delayed timestamp is worse than a fresh one | Polling again and discarding poor samples | ## What an interviewer is listening for - The **handshake cost relative to the exchange**: one extra round trip doubles the latency of a one-round-trip lookup. - **Statelessness** on a server that talks to huge numbers of clients. - **Broadcast** as a hard requirement that TCP cannot meet. - The nuance that DNS uses TCP too, for truncated responses, zone transfers and, since RFC 7766, any query a resolver chooses to send that way.
- Is DNS a UDP-only protocol?No. RFC 1035 caps a DNS message over UDP at 512 bytes; a longer response is truncated with the TC bit set and the client retries over TCP. Zone transfers always use TCP. RFC 7766 requires all general-purpose DNS implementations to support both transports, lets resolvers send any query over TCP, and requires servers to answer on the transport the query arrived on.
- Why would a TCP retransmission hurt NTP's accuracy rather than help it?NTP estimates clock offset from timestamps at both ends, assuming the delay is roughly symmetric. A reply held back by a retransmission, or queued behind a lost segment, arrives with extra one-way delay that skews the estimate. The data arrives, but its timing is wrong, so dropping the exchange and taking the next sample gives a better result.
saying these in an interview costs you the question
- DNS uses UDP only and never falls back to TCP
- A resolver must always send a UDP query before it may use TCP
- DHCP could run over TCP if the server listened on a known port
- TCP retransmission would make NTP more accurate because no sample is lost
- UDP makes DNS unreliable, so lost lookups simply fail