Quick revision
The short answer
Traffic keeps arriving because many clients never ask DNS again: some resolvers and apps cache beyond the TTL, the JVM caches lookups per networkaddress.cache.ttl, partners may pin addresses, and long-lived HTTP keep-alive pools, gRPC channels and WebSockets keep using the old address until the connection breaks. To fail over faster, we make the endpoint independent of DNS with anycast or a global load balancer whose addresses stay the same, and we make clients behave by limiting connection lifetime, re-resolving after errors, and testing failover with real client types.
What to remember
In this answer, we saw that a TTL only matters for clients that respect it and ask again, while resolvers, the JVM's networkaddress.cache.ttl, applications that pin addresses and long-lived connections keep using the old region. The strongest fix is stable anycast or global load balancer addresses so failover does not depend on DNS, together with clients that limit connection lifetime, re-resolve and retry after errors, and failover drills that measure real client types.
Your turn
Answer it aloud as you would in the interview, or type your answer below. Then show one part at a time and compare.
Traffic keeps arriving because many clients never ask DNS again: some resolvers and apps cache beyond the TTL, the JVM caches lookups per networkaddress.cache.ttl, partners may pin addresses, and long-lived HTTP keep-alive pools, gRPC channels and WebSockets keep using the old address until the connection breaks. To fail over faster, we make the endpoint independent of DNS with anycast or a global load balancer whose addresses stay the same, and we make clients behave by limiting connection lifetime, re-resolving after errors, and testing failover with real client types.
Why this question is asked
Lowering the TTL feels like the obvious way to speed up failover, and then an outage shows that a 60-second TTL moved only part of the traffic in 20 minutes. Interviewers ask this because the answer is not in the DNS server at all; it is in every layer that caches or holds connections. In this answer, we will walk through where stale addresses live, look at the Java settings in particular, then fix the problem from the server side with stable addresses and from the client side with connection lifetimes and retries.
1A Quick Recap: What the TTL Actually Controls
The TTL on a DNS record tells resolvers how long they may cache the answer. Changing the record therefore affects a client only when two things happen: its cached answer expires, and it looks the name up again. The TTL controls the first part, and only for clients that respect it. It does nothing for the second part. A client that resolved the name once and kept the address, or that holds an open connection, has no reason to ask DNS anything.
So the 15 percent of traffic still hitting the dead region after 20 minutes is not a DNS failure. Those clients simply never asked again.
2Where the Old Address Lives On
There are several layers where an old answer survives. Some recursive resolvers enforce a minimum cache time longer than our 60 seconds. Operating systems and client libraries keep their own caches. Some applications resolve the name at startup and keep the address for the life of the process. Mobile apps may cache endpoints in local storage, or even ship with a hard-coded address list as a fallback.
The biggest layer is long-lived connections. An HTTP client with keep-alive keeps a pool of open TCP connections and reuses them for many requests. A gRPC channel holds one connection for hours. A WebSocket stays open as long as the app is in the foreground. None of these look up DNS while the connection is alive, and if the dead region's addresses still accept TCP, for example at a load balancer that is up while the services behind it are down, connections may not even break.
- Recursive resolvermay cache longer than the TTL
- JVM or OS cache
networkaddress.cache.ttl, OS resolver caches - Applicationresolves once at startup, pins addresses
- Connection poolkeep-alive connections reuse the old IP
- Long-lived streamsgRPC channels and WebSockets stay open
5 layers, from the top down. Step through them one at a time.
A DNS change reaches a client only after every layer above it lets go.
Notice how this matches what the team saw: mobile apps and partner backends are exactly the clients that hold connections and caches the longest, while browsers, which re-resolve often, moved quickly.
3Java Clients in Particular
The JVM keeps its own cache of successful lookups, controlled by the security property networkaddress.cache.ttl. In current OpenJDK the default is 30 seconds when no value is set, but older platforms and some application servers set it much higher, and setting it to -1 means cache forever. A partner backend with a large value, or one that resolved the name into a fixed configuration, will keep the old address regardless of our TTL.
Even with a sensible DNS cache, a pooled HTTP client keeps using connections it already has. The fix on the client is to give connections a maximum lifetime, so the pool closes them and opens new ones, which triggers a fresh lookup.
Apache HttpClient and OkHttp have equivalent settings for connection time to live; the names differ, so check your version. For gRPC, the server can set a maximum connection age so clients reconnect periodically and pick up new addresses.
4Fix 1: Stop Depending on DNS for Failover
The most effective change is architectural. If the public endpoint is a set of stable addresses that never change, failover does not need DNS at all. A global load balancer or an anycast edge, such as AWS Global Accelerator, a cloud provider's global HTTP load balancer, or a CDN fronting the API, gives us fixed addresses announced from many locations. Behind them, the edge chooses a healthy region per connection. When a region fails, the edge stops sending new connections there within seconds, and clients with cached addresses keep working because the address is still valid.
Existing connections to the failed region still need to break, but the edge usually terminates them close to the user, so it can close them deliberately and the client reconnects to the same address, landing in a healthy region.
5Fix 2: Make Clients Behave and Test With Real Clients
For clients we control, we set three behaviours. Limit connection lifetime, as above, so pools re-resolve every few minutes. Treat connection errors and timeouts as a reason to discard the connection, look up the name again and retry once, for idempotent requests. And never hard-code addresses in mobile apps; if a fallback is needed, make it a list served from configuration that we can update.
Then test failover with the real client types, not by checking that dig returns the new address. A drill that drains a region in staging should measure traffic still arriving per client type, the mobile app, each partner, internal services, after 1, 5 and 20 minutes. That turns the tail we saw in the incident into a number we can track and push down.
6Follow-up questions
How would you tell partners what client settings to use?
Publish an integration guide with concrete values and the reason for each: a JVM DNS cache of at most 60 seconds, a connection maximum lifetime of a few minutes, re-resolve and retry once on connection errors, no IP pinning or allow-listing of our addresses, and a list of the stable anycast addresses if they need firewall rules. Then back it with evidence: during failover drills, send each partner a report of how long their traffic took to move, so the settings are verified rather than just documented.
Would a TTL of 5 seconds solve the problem?
No. It would raise DNS query volume and cost a lot, and it would only speed up the clients that already respect the TTL and look up again, which were not the problem. The stale 15 percent came from caches that ignore the TTL and from long-lived connections, which a shorter TTL does not touch.
7Conclusion
In this answer, we saw that a TTL only matters for clients that respect it and ask again, while resolvers, the JVM's networkaddress.cache.ttl, applications that pin addresses and long-lived connections keep using the old region. The strongest fix is stable anycast or global load balancer addresses so failover does not depend on DNS, together with clients that limit connection lifetime, re-resolve and retry after errors, and failover drills that measure real client types.
Open with
The TTL only controls how long a resolver may cache the answer. Traffic moves only when a client's cache expires and it actually looks the name up again, and many clients never do.
Then, if they want more
Some resolvers and apps cache longer than the TTL, the JVM caches lookups according to networkaddress.cache.ttl, which partners may have set high or to forever, and some apps resolve once at startup or even hard-code addresses.
The biggest factor is long-lived connections: keep-alive pools, gRPC channels and WebSockets keep talking to the old address without touching DNS until the connection breaks. That is why mobile apps and partner backends made up the stale 15 percent.
To fail over faster, I would make failover independent of DNS, using anycast or a global load balancer with stable addresses, so the endpoint stays the same and the edge sends new connections to a healthy region in seconds.
On the client side, I would set a maximum connection lifetime of a couple of minutes so pools re-resolve, re-resolve and retry once on connection errors for idempotent calls, and publish these settings for partners. Then I would test failover with real client types and measure how much traffic each still sends after 1, 5 and 20 minutes.
About this answer
- Last updated
- 13 November 2026
- Checked
- Its structure and format are checked automatically. Use it as a carefully prepared study note: where a detail matters, confirm it against the official documentation for the version you use. What the checks cover
- Where the question comes from
- Written by Scrivio for practice. It is not taken from an interview.
Report an issue with this answer
Copy the line below and send it to the author with what you found. It carries the address of this page.
Issue with "Why does traffic keep going to the old addresses, and how would you make failover faster?": https://scrivio-interview-library.netlify.app/architecture/load-balancing-networking/5f137aaa40/