The symptom#
You created orders-db.example.internal at 10:00, and the orders service still fails at 10:06 with a name-not-known error. A colleague's laptop resolves it. Some pods resolve it and others do not.
Two causes look identical from the client:
- The record exists at the authoritative servers, but a resolver on the client's path cached a negative answer from a lookup made before the record existed.
- The record does not exist where the resolver looks: it went into the wrong zone, a zone not associated with this network, or a change that has not finished propagating.
The first fixes itself when the negative TTL runs out. The second does not.
How negative caching works#
RFC 2308 lets resolvers cache NXDOMAIN (the name does not exist) and NODATA (the name exists, but not with this type). An authoritative server includes the zone's SOA record in the authority section of a negative response, and the time a resolver may cache the negative answer is the minimum of the SOA's MINIMUM field and the TTL of the SOA record itself. The TTL counts down in the cache like any other, and the negative answer must not be used once it reaches zero. RFC 2308
The numbers can be large. Route 53 creates each hosted zone with an SOA whose MINIMUM is 86400 seconds and whose own TTL defaults to 900 seconds, so a negative answer from a default Route 53 zone is cached for up to 15 minutes. Route 53 SOA record
A negative answer can also be cached at more than one level. CoreDNS's cache plugin caches denial-of-existence responses for up to 1800 seconds by default, capped by the record's own negative TTL, and the JVM caches failed lookups for 10 seconds by default through networkaddress.cache.negative.ttl. CoreDNS cache plugin · Java networking properties
The usual way a cache gets poisoned with a negative answer is a lookup that ran before the record existed: a deploy script that checks whether the name resolves, a health check that started early, or a service that started before the infrastructure change finished.
Ask the authority, then the resolver#
Find the zone's authoritative servers and ask one of them with recursion turned off. Then ask the resolver the client uses. dig manual
dig @RESOLVER_IP example.internal NS +short
dig @AUTHORITATIVE_NS orders-db.example.internal A +norecurse
dig @RESOLVER_IP orders-db.example.internal A
In a negative reply from the resolver, look at the authority section. The SOA there names the zone that produced the answer, and its TTL is the time left on the cached negative entry. Run the query twice a few seconds apart: a TTL that goes down confirms you are reading a cache.
;; AUTHORITY SECTION:
example.internal. 612 IN SOA ns-1.example.internal. hostmaster.example.internal. 1 7200 900 1209600 86400
For a Route 53 zone, also read the zone's SOA, the record and the change status through the API. A private zone is answered only by the VPC resolver, so this is how you see what it holds. PENDING means the change has not yet reached all Route 53 servers for the zone; INSYNC means it has. list-resource-record-sets · get-change
aws route53 list-resource-record-sets \
--profile PROFILE --hosted-zone-id ZONE_ID \
--query "ResourceRecordSets[?Type=='SOA'].{name:Name,ttl:TTL,value:ResourceRecords[0].Value}" \
--output json --no-cli-pager
aws route53 list-resource-record-sets \
--profile PROFILE --hosted-zone-id ZONE_ID \
--query "ResourceRecordSets[?Name=='orders-db.example.internal.']" \
--output json --no-cli-pager
aws route53 get-change --profile PROFILE --id CHANGE_ID --no-cli-pager
Read the result#
| Authority | Resolver | Points to |
|---|---|---|
| Record | NXDOMAIN, SOA TTL counting down | Cached negative answer; wait out the TTL |
| Record | NXDOMAIN, SOA of another zone | The resolver uses a different zone for this name |
| NXDOMAIN | NXDOMAIN | The record is not in the zone the authority serves |
| Record | Record, client still fails | A cache inside the client or runtime |
The second row is common with private zones: a resolver inside a VPC consults the private zone for example.internal, while your laptop asks the public one. Private hosted zone not resolving · Split-horizon answers
For the general reading of DNS status codes, see NXDOMAIN, SERVFAIL or no answer.
A worked example: two records created at 10:00#
This example is illustrative. A pipeline creates orders-db.example.internal in a Route 53 private zone at 10:00:05 UTC. Its last step, at 10:00:01, ran a smoke check that resolved the name and failed, as expected, because the record did not exist yet.
At 10:06, from an orders task:
| Query | Result |
|---|---|
get-change for the 10:00:05 change | INSYNC |
| Resolver 10.0.0.2, A | NXDOMAIN; SOA of example.internal, TTL 535, then 529 six seconds later |
list-resource-record-sets for the name | A record, 10.0.14.21 |
The zone holds the record and the change has propagated. The resolver is serving the negative answer cached at 10:00:01, with 535 seconds left: 10:00:01 plus the 900-second SOA TTL is 10:15:01. The orders service will resolve the name at about 10:15 without any change. Moving the smoke check after the record creation avoids the wait next time.
In a second incident the same check shows the resolver's NXDOMAIN carrying the SOA of example.com, not example.internal, with a TTL that does not count down between queries. The record went into a zone this VPC never consults. Waiting will not help; the record needs to be in the zone the VPC uses.
Limits#
You cannot flush a resolver you do not operate. Plan for the negative TTL when you create names that clients may have asked for already.
The countdown shows the cache of the resolver you queried. A client may go through more than one cache, such as a node-local cache, CoreDNS and the VPC resolver, each with its own timer. Query each layer you can reach.
Lowering the SOA's TTL or MINIMUM shortens negative caching for every name in the zone, and it takes effect only once resolvers stop caching the old SOA. Route 53 charges negative responses at the standard query rate, so shorter negative caching means more billed queries. Route 53 SOA record For the rest of the dependency checks, see runtime dependency failures.
Questions#
How long does a negative DNS answer stay cached?
For the lesser of the SOA's MINIMUM field and the SOA record's own TTL, as returned by the authoritative server. Read the SOA in the authority section of the negative reply to see the remaining time.
Why does my laptop resolve the new record when the service cannot?
Your laptop uses a different resolver that never cached the negative answer, or a different zone altogether. Query the service's resolver from inside its network to see what the service sees.
Does negative caching apply to a missing AAAA record?
Yes. A name with an A record and no AAAA record returns NODATA for AAAA, and resolvers cache that for the same negative TTL.