DNS Negative Caching for NXDOMAIN and NODATA
DNS negative caching is the practice of caching a DNS answer that says something is missing. A resolver can cache both NXDOMAIN—the requested name does not exist—and NODATA—the name exists, but it has no record of the requested type.
This saves repeated queries for names that are known not to exist, but it also explains a common incident: you create or repair a DNS record, yet some clients continue to receive a negative answer for minutes or hours.
The problem negative caching solves
DNS usually involves more than the client and the server hosting a domain. A client asks a recursive resolver, a DNS service that finds answers on the client’s behalf and caches them. The resolver may serve many applications, hosts, or customers.
Without negative caching, every request for a typo, an abandoned hostname, or a deliberately nonexistent record would require another lookup through the DNS hierarchy. A popular nonexistent name could generate just as much traffic as a popular existing one. Negative caching lets the resolver remember the result and answer locally until that result expires.
The trade-off is that “does not exist” is not permanent. DNS data can be added or repaired later, but a resolver that cached the earlier negative result does not know that unless it asks again.
Two different negative answers
Suppose a client asks for api.example.com with record type A, which normally contains an IPv4 address.
- NXDOMAIN means the DNS name itself does not exist. The authoritative server—the server responsible for the domain’s data—has established that
api.example.comis not a name in that domain. - NODATA means the name does exist, but there is no record of the requested type. For example,
api.example.commight have anAAAArecord for IPv6 and noArecord for IPv4.
These answers are not interchangeable. A name that returns NODATA may still return useful data when queried for another type. NXDOMAIN says the name is absent altogether, though DNS also has rules for proving that a wildcard cannot supply an answer.
Both kinds of negative response can be cached. A resolver must retain enough information to avoid treating a cached NODATA result as proof that the entire name is nonexistent, or treating an NXDOMAIN result as merely “this one record type is absent.”
Where the negative TTL comes from
A cached DNS result has a TTL, or time to live: the number of seconds the result may be reused before it must be considered expired. For negative answers, the authoritative server supplies the timing information through an SOA record (Start of Authority), a record containing administrative information about a DNS zone.
The negative response normally includes the zone’s SOA record in its authority section. The resolver uses that SOA information to determine how long it may cache the NXDOMAIN or NODATA result. In RFC 2308-style processing, the effective negative TTL is bounded by the SOA record’s own TTL and its MINIMUM field; resolver configuration can impose additional minimum or maximum limits.
The important operational point is that negative caching is controlled by the authoritative zone, not by the client that happened to make the failed request. A response might look conceptually like this:
;; status: NXDOMAIN
;; AUTHORITY SECTION:
example.com. 900 IN SOA ns1.example.com. hostmaster.example.com. ... 300
Here, 900 is the TTL on the SOA record and 300 is the SOA MINIMUM value. Under the usual bounded calculation, the negative result can be cached for 300 seconds. Exact behavior can also be affected by the recursive resolver’s policy, so the authoritative value is not always the final value seen in an incident.
The SOA record is not an answer saying that the missing name exists. It is evidence accompanying the negative answer, plus the expiration information needed to cache that answer safely.
What happens after a failed lookup
The sequence is:
- A client asks its recursive resolver for a name and type.
- The resolver queries the authoritative server if it has no usable cached result.
- The authoritative server returns NXDOMAIN or NODATA, with SOA information in the authority section.
- The resolver stores the negative result and its expiration time.
- Further clients asking the same question receive the cached negative response without causing another authoritative lookup.
- When the negative TTL expires, the resolver queries again and can discover newly published data.
Resolvers may also cache related proof about the name, such as information showing that a particular domain label does not exist. This is why the effect can sometimes appear broader than one application request, while still being governed by the same expiration rules.
Why a repaired name stays unavailable
Imagine that payments.example.com was accidentally deleted. A monitoring system, deployment tool, or user queries it during the deletion window. The authoritative server returns NXDOMAIN with a negative TTL of one hour. The record is then recreated correctly five minutes later.
The resolver that made the original query still has a valid cached statement that the name does not exist. It will continue returning NXDOMAIN for the remainder of that hour. The new record is present at the authoritative server, but that resolver is not checking yet.
Different resolvers may have made their first failed lookup at different times, so clients do not recover simultaneously. A local operating-system cache, browser cache, service-side DNS cache, or another forwarding resolver can add another layer of delay. Testing from one network may therefore succeed while users on another network still see the old negative answer.
When investigating this symptom, check the response status—NXDOMAIN versus NODATA—the SOA data in the negative response, and which resolver the affected client is using. A successful lookup directly against an authoritative server proves that the repair is published there; it does not prove that every recursive resolver’s negative cache has expired.