Interview Prep/Real-World Interview/DNS, TLS and certificates

After a database was migrated to a new host behind the same DNS name, one Java service keeps connecting to the old IP until it's restarted.

IntermediateTroubleshootingDNS, TLS and certificates
Answer

Likely causes → The application caches DNS too long. The JVM caches lookups per networkaddress.cache.ttl (forever when a SecurityManager is installed, 30 seconds by default otherwise, but frameworks and connection pools often resolve once and keep the address). Long-lived pooled connections also never re-resolve.

Diagnose →

kubectl exec deploy/billing -- getent hosts db.internal.example.com
kubectl exec deploy/billing -- ss -tnp | grep 5432      # which IP it's really connected to

Check java.security for networkaddress.cache.ttl and the pool's max connection lifetime.

Fix → Restart the service now. Then set networkaddress.cache.ttl=30 and a pool maxLifetime (HikariCP default 30 minutes) so connections recycle and re-resolve.

Prevent → Include "who caches this DNS name?" in every migration plan, and keep the old endpoint alive (or redirecting) until all clients have moved.

All Real-World Interview questions Roadmap: Interview readiness

More on DNS, TLS and certificates