Application-level DNS caching
The JVM
Java caches successful lookups according to networkaddress.cache.ttl (in java.security or set programmatically):
- Default: 30 seconds in modern JDKs when no security manager is installed.
-1= cache forever (until the JVM restarts) — historically the default when a security manager was installed, and sometimes set explicitly by old app servers.- Negative lookups:
networkaddress.cache.negative.ttl(default 10 s).
AWS recommends a TTL of 60 seconds or less for Java apps talking to AWS endpoints.
java.security.Security.setProperty("networkaddress.cache.ttl", "60");
# or in $JAVA_HOME/conf/security/java.security
networkaddress.cache.ttl=60
Classic incident: "A Java service fails after the ALB scaled" — it pinned old ELB IPs forever. Fix the cache setting and restart.
Other runtimes
- Node.js —
dns.lookup(used byhttp) calls the OS resolver every time; no built-in cache (usecacheable-lookupor an agent if you need one). Without an OS cache in a container, every request triggers a DNS query — significant load on CoreDNS. - Go — the pure-Go resolver doesn't cache; relies on the OS/cluster DNS.
- Python — no cache by default (requests each
getaddrinfo). - .NET —
ServicePointManager.DnsRefreshTimeout(older),SocketsHttpHandler.PooledConnectionLifetimein modern .NET.
Connection pools pin IPs regardless of DNS
Even with perfect DNS caching, a long-lived connection keeps talking to the IP it connected to. HTTP keep-alive pools, database pools and gRPC channels may never re-resolve. Set a maximum connection lifetime (e.g. 5–10 minutes) so connections are periodically recreated and pick up new DNS answers — important for RDS failover (the endpoint's CNAME flips to the new primary) and for load balancers whose IPs change.
Mobile and IoT clients
Apps that cache resolved IPs for hours — or hardcode them — ignore TTL entirely. During migrations keep the old endpoint alive (or redirect/proxy from it) until old app versions age out, and design clients to re-resolve on failure.