Opscraft
DNS

DNS TTL & caching

Must-know8 lessons · 25 min · 3 tests ·

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.

Stage 1 · Foundations

Know these first

After this topic you can

  • Explain caching and TTLs at every level
  • Plan a DNS change or migration with low TTLs
  • Debug "some users still see the old IP"

Lessons

  1. 1What a TTL is 3 min read
    • A per-record cache lifetime
    • Reading TTLs with dig
    • Who sets and who obeys
  2. 2The cache hierarchy 3 min read
  3. 3Negative caching 3 min read
  4. 4Propagation and planning changes 4 min read
    • "Propagation" is really expiry
    • A migration timeline
    • Name server (delegation) changes
    • Verifying propagation
  5. 5Choosing TTLs 3 min read
    • Trade-offs
    • Sensible defaults
    • Cost on Route 53
  6. 6TTL, failover and load balancing on AWS 3 min read
    • DNS failover is bounded by TTL
    • Why ELB IPs change and why aliases matter
    • DNS switch vs load balancer switch
    • Lessons from incidents
  7. 7Application-level DNS caching 3 min read
    • The JVM
    • Other runtimes
    • Connection pools pin IPs regardless of DNS
    • Mobile and IoT clients
  8. 8Interview questions and model answers 3 min read
    • "What is DNS TTL and who controls it?"
    • "Why does DNS propagation take up to 48 hours?"
    • "You need to move a record to a new IP tomorrow. How do you prepare?"
    • "We changed the record ten minutes ago but some users still hit the old IP. The old TTL was 3600. Is something wrong?"
    • "You created a record, but it still returns NXDOMAIN for some people. Why?"
    • "How does TTL affect failover?"
    • "A Java service keeps calling an old load balancer IP after the ALB scaled. Fix?"
    • "Why can't you set a custom TTL on a Route 53 alias to an ALB?"