DNS TTL
Time To Live for DNS records—how long resolvers and clients should cache a DNS response before querying again. Measured in seconds. Short TTLs enable fast failover; long TTLs reduce DNS query load.
Full Explanation
DNS TTL is a balancing act. Set it too long (hours/days) and you can't quickly reroute traffic when things break. Set it too short (seconds) and you increase DNS query volume and add latency from frequent lookups.
For CDN CNAMEs, 300 seconds (5 minutes) is a common sweet spot. Fast enough to reroute in an emergency, long enough that DNS isn't a bottleneck. If you're planning a CDN migration, lower the TTL to 60s a day before the switch so records propagate quickly.
Important distinction: DNS TTL is about how long the DNS answer is cached. It's completely separate from HTTP caching TTL (Cache-Control max-age), which is about how long content is cached. They're often confused but control entirely different things.
See the interactive TTL Countdown animation in the course to visualize how TTL expiration works.
Interactive Animation
Examples
# Set DNS TTL in a zone file
www.example.com. 300 IN CNAME cdn.example.com.cdn77.org.
# ^^^ TTL in seconds (5 minutes)
# Before a CDN migration, lower TTL
www.example.com. 60 IN CNAME old-cdn.example.com.
# Wait 24h for old TTL to expire, then switch
www.example.com. 60 IN CNAME new-cdn.example.com.
# After migration is stable, raise TTL back
www.example.com. 3600 IN CNAME new-cdn.example.com.
# Check current TTL
$ dig www.example.com | grep -A1 'ANSWER'
www.example.com. 247 IN CNAME cdn.example.com.
# ^^^ remaining TTL (counting down)
Video Explanation
Frequently Asked Questions
Time To Live for DNS records—how long resolvers and clients should cache a DNS response before querying again. Measured in seconds. Short TTLs enable fast failover; long TTLs reduce DNS query load.
# Set DNS TTL in a zone file
www.example.com. 300 IN CNAME cdn.example.com.cdn77.org.
# ^^^ TTL in seconds (5 minutes)
# Before a CDN migration, lower TTL
www.example.com. 60 IN CNAME old-cdn.example.com.
# Wait 24h for old TTL to expire, then switch
www.example.com. 60 IN CNAME new-cdn.example.com.
# After migration is stable, raise TTL back
www.example.com. 3600 IN CNAME new-cdn.example.com.
# Check current TTL
$ dig www.example.com | grep -A1 'ANSWER'
www.example.com. 247 IN CNAME cdn.example.com.
# ^^^ remaining TTL (counting down)