Systems and protocols · Intermediate

DNS: resolution, delegation and caching

Follow a name through recursive resolution, authoritative delegation and time-limited caches.

Ask Logeia about this articleTry the three questionsReview your answers

Updated

On this page
  1. Who answers a name?
  2. A delegation example
  3. TTL and checking a change
  4. Limits of the result
  5. Calculate remaining TTL across a change
  6. Compare the same name, type, and observation point
  7. Distinguish a missing name from a missing record type
  8. Plan both the transition and the rollback
  9. Exercise: two resolvers and an alias change
  10. Ask Logeia about this articleCheck your understanding

Who answers a name?

DNS maps names to resource records, including addresses, through a distributed namespace. A typical application asks a local stub resolver, which sends a query to a recursive resolver. That resolver performs the necessary lookup work and returns an answer. The authoritative server is responsible for the contents of a particular zone; it is not the same role as the recursive resolver.

This separation matters during troubleshooting. An application can receive a cached answer without contacting the authoritative server on that request. Changing an authoritative record therefore does not imply that every client immediately observes the new value.

A delegation example

Consider an A lookup for api.example.com. With an empty cache, a resolver may obtain referrals from the root and com servers before reaching the server responsible for example.com. Cached delegation information can skip some of those steps. The sequence is a dependency chain, not a requirement to contact every level for every query.

A records contain IPv4 addresses, while AAAA records contain IPv6 addresses. A CNAME identifies another name and can require another lookup. Even a successful address answer says nothing about whether a web application is listening at that address.

TTL and checking a change

A record TTL bounds ordinary cache reuse. If a resolver cached the old record with a long TTL, editing the authoritative zone does not reach into that cache and replace it. Lowering a TTL immediately before a migration also cannot retroactively shorten previously cached copies.

Compare the authoritative answer with the answer from the recursive resolver actually used by the client. If both are current but the application behaves differently, inspect application caching and connection reuse before concluding that delegation is broken.

Limits of the result

A missing name and a temporary lookup failure are different outcomes. Negative answers can also be cached, so repeatedly querying a missing record may not force a new authoritative lookup. Preserve the response status when investigating a failure.

Ordinary resolution is not application authentication. HTTPS still needs certificate validation and an appropriate trust decision. Check resolution, transport connection, TLS and HTTP separately; success at an earlier stage does not establish success at a later stage.

Calculate remaining TTL across a change

Suppose a resolver receives an A record at time zero with TTL 300 seconds. At time 120 the authoritative data changes and its newly served TTL becomes 60 seconds. That update does not retroactively change the lifetime of the answer already cached with TTL 300. If the resolver retains and normally reuses that answer, it can still return the old address at time 200 with about 100 seconds remaining. A new authoritative TTL affects new caching events, not every old answer simultaneously.

Lowering TTL before a planned change therefore requires time for earlier answers to age out. Different users can consult different resolvers, and endpoint or application caching can add another layer. Stale-answer policies under failure can also complicate observations. The table is a worked model of ordinary TTL reuse at one resolver, not a promise that every implementation always retains data until expiration. Compare timestamp, queried resolver, record type and remaining TTL, and distinguish a direct authoritative query from a lookup through a recursive cache.

TimeObserved state
0 sCache old answer with TTL 300
120 sAuthoritative answer changes; new TTL is 60
200 sOld cached answer has about 100 s remaining
After 300 sOriginal normal reuse lifetime has expired

Compare the same name, type, and observation point

When only some clients reach an old address, compare the same fully qualified name and record type first. Checking A records does not explain a connection that actually used AAAA. Then distinguish the authoritative answer, the answer from the client’s recursive resolver, and the address actually used by the application. A CNAME and its target can have different cached lifetimes. Record the observation time, queried server address, response code, returned records, and remaining TTL. This gives a chain of evidence rather than a collection of unrelated screenshots. Clearing one local cache can be a diagnostic intervention, but it does not establish which other caches or existing connections are still in use.

Distinguish a missing name from a missing record type

NXDOMAIN reports that the queried name does not exist. A name can instead exist without the requested record type; an empty answer section alone does not distinguish every situation. SERVFAIL and a timeout invite other hypotheses, including reachability, validation, and resolver operation. Negative caching has its own lifetime rules involving SOA information. A newly created name may therefore remain unavailable to a resolver that recently cached its absence. Lowering a positive A-record TTL does not retroactively shorten a previously cached negative answer. Read the response code and authority information together, and investigate the actual resolver path before changing unrelated zone data.

Plan both the transition and the rollback

A migration plan asks whether old and new endpoints can coexist, whether the new endpoint has the right certificate, and whether HTTP works along the new path. If the old lifetime was one hour, distribute a shorter lifetime early enough to allow ordinarily cached old answers to expire before the change. This is still not a universal completion deadline: implementations can serve stale information under specified failure conditions, and applications may cache independently. Observe errors and traffic at both destinations. Rolling the authoritative record back does not instantly reverse answers already cached from the new state or close established connections. Treat DNS as one part of the service transition rather than as a global remote-control switch.

Exercise: two resolvers and an alias change

Suppose api.example is a CNAME for old.example, whose A record contains the old address. At time zero resolver R1 stores the CNAME with TTL 300 and the A record with TTL 60. Resolver R2 stores the same CNAME at time 240 with TTL 300, then fetches its target address. At time 250 the authoritative CNAME changes to new.example. Both web services work; exclude additional application caching and serving expired records. Must both resolvers use the new target at time 310?

No. R1's alias expires at time 300 and can be refreshed to the new target on a subsequent request. R2's alias can remain valid until 540. Expiry of the old A record does not expire the separately cached CNAME. R2 can fetch old.example's address again and continue using the old target. Time passing alone does not cause the exercise to issue a query; consider a new request at the stated time. The table therefore does not justify shutting down the old destination at 310.

Now suppose R2 cached NXDOMAIN for new.example before that name was published. Creating the name does not necessarily make R2 obtain its positive answer immediately. Inspect the remaining negative-cache lifetime as a separate dependency. A new alias is not proof that its target is usable. In an actual investigation also align A versus AAAA, the original service name used for TLS identity verification and the HTTP host field. Resolving an alias does not replace those later protocol checks.

For a rollback exercise, assume errors rise at the new service at time 400. Does restoring the authoritative CNAME instantly restore every request? The model answer is no: resolvers may retain the new alias, and established connections can remain. Plan how long both destinations must function and retain observations identifying which destination failed. The exercise intentionally makes cache entries and query times explicit so the answer follows from their separate lifetimes. A TTL calculation supports the decision; it does not by itself establish that an operational rollback has finished for every client.

TimeR1R2
250Old alias; expires at 300Old alias; expires at 540
New request at 310Can refresh to new aliasCan refetch the old target A
New request after 540Uses the then-applicable answerOld alias lifetime has ended

Reading and practice are recorded separately in this browser, for each language.

Learn this in order

Understand the systems behind the web · STEP 10

Choose a learning path