What a TTL is
TTL — time to live — is the number that tells every DNS cache how long it may keep an answer. It's why "DNS propagation takes up to 48 hours", why a failover can take five minutes to reach users, why you lower TTLs before a migration, and why a Java service keeps calling an old load balancer IP. Senior engineers are expected to plan DNS changes around TTLs, design failover with realistic switch times, and know every layer that caches DNS answers — including the ones that ignore TTL entirely.
A per-record cache lifetime
Every DNS resource record carries a TTL in seconds, set by the zone owner on the authoritative server:
; zone file
shop.example.com. 300 IN A 203.0.113.10
www.shop.example.com. 3600 IN CNAME shop.example.com.
example.com. 86400 IN MX 10 mail.example.com.
300→ caches may keep the answer for 5 minutes;3600= 1 hour;86400= 1 day.- TTL applies to the whole record set (all A records for a name share one TTL).
- A CNAME and its target each have their own TTL; a resolver caches each part independently.
- Route 53 alias records have no TTL of their own — Route 53 uses the target's TTL (e.g. 60 s for ELB records), which you can't change.
Reading TTLs with dig
$ dig shop.example.com
;; ANSWER SECTION:
shop.example.com. 247 IN A 203.0.113.10
The number after the name is the remaining TTL in the cache that answered. Ask the same recursive resolver again a few seconds later and it counts down (247, 240, 233...). When it reaches 0, the resolver must fetch the record again from the authoritative server. Querying the authoritative server directly shows the full configured TTL:
dig +noall +answer shop.example.com # via your resolver (remaining TTL)
dig +noall +answer shop.example.com @8.8.8.8 # what Google's resolver currently caches
dig NS example.com +short # find the authoritative servers
dig +noall +answer shop.example.com @ns-1234.awsdns-12.org # configured TTL from the source
Who sets and who obeys
- The zone owner sets TTLs (you, in Route 53).
- Caches obey — mostly. Resolvers may apply minimum and maximum caps (some resolvers enforce a floor of 30–60 s, many cap at a day or a week), browsers have their own fixed caches, and some applications ignore TTL entirely (see the application lesson).
- TTL 0 means "don't cache" — legal, but some resolvers cache briefly anyway, and it maximises query load.