When an external partner's AWS ALB (`api, fix both layers: bound JVM DNS cache TTL (<=30s) AND bound HTTP connection max-lifetime (connTTL ~55s + jitter) so persistent TCP/TLS sockets actually re-resolve rotated ALB IPs.
TL;DR30-second simplified summary▾
Core Mechanics: When an external partner's AWS ALB (api.partner-pay.com, DNS TTL = 60 s) scales or rotates IPs, old IPs are drained and decommissioned 5 minutes later.
Visual & Structural Flow: Depicts ALB IP Rotation: Pinned TLS Socket (504) vs. Bounded connTTL + DNS TTL (Java Pod (100 conns) -> NodeLocal DNS (60s) -> Old ALB IP -> New ALB IP); NodeLocal DNS -> JVM Cache (30s) -> Jittered connTTL (55-75s) (App Threads -> HttpClient Pool -> JVM DNS Cache -> NodeLocal DNS).
Trade-Offs & Production: Setting Connection: close or networkaddress.cache.ttl=0 trades outages for latency and CoreDNS saturation: TLS 1.3 Handshake Tax: Disabling keep-alive adds ~18 ms RTT to every single partner call. Production Java clients combine three coordinated settings:
Failure Modes & Application: Coordinated DNS + connection-pool TTLs are critical whenever talking to elastic cloud endpoints: AWS ALB / NLB & CloudFront Integrations: Following elastic load balancer node scaling without 504s.
Why stale DNS breaks long-lived HTTP/2 and TLS clients.
Why this matters: The mechanism: understand how Why stale DNS breaks long-lived HTTP/2 and TLS clients works from first principles.
Think of Why stale DNS breaks long-lived HTTP/2 and TLS clients as the intuition layer for Fixing Stale DNS Caching in Long-Lived Clients: The mechanism: understand how Why stale DNS breaks long-lived HTTP/2 and TLS clients works from first principles.
When an external partner's AWS ALB (api.partner-pay.com, DNS TTL = 60 s) scales or rotates IPs, old IPs are drained and decommissioned 5 minutes later. Long-lived Java pods (200 pods × 100 persistent TLS connections) keep sending 100% of traffic to dead IPs—causing ConnectTimeoutException and 504 Gateway Timeout until pods are manually restarted.
What happens when DNS TTL and connection pools are unbounded.
Why this matters: The problem: see what breaks without What happens when DNS TTL and connection pools are unbounded under real concurrency or scale.
Two independent caching layers pin traffic to dead ALB nodes:
- JVM
InetAddressCache: With a SecurityManager or older defaults, Java caches DNS forever; even with30 sdefault, it only applies to new socket connections. - Unbounded Keep-Alive Socket Lifetime: Existing TLS 1.3 sockets stay open indefinitely, never performing a new DNS lookup even after the JVM DNS cache expires.
ALB IP Rotation: Pinned TLS Socket (504) vs. Bounded connTTL + DNS TTL
Bounding both JVM DNS TTL (30s) and pooled connection max-lifetime (55s + jitter) rotates traffic within 60s without TLS storms.
- Problem
- How to implement Fixing Stale DNS Caching in Long-Lived Clients without hitting unbounded tail latency, state divergence, or operational fragility.
- Naive Solution
- Use a single unpartitioned path with unbounded retries and synchronous global coordination.
- Why It Fails
- Global coordination serializes throughput under load, while unbounded retries amplify transient stalls into full outages.
- Alternatives
- Compare synchronous strict-consistency paths against bounded asynchronous replication, local caching, or partitioned ownership.
- Engineering Decision
- When an external partner's AWS ALB (`api, fix both layers: bound JVM DNS cache TTL (<=30s) AND bound HTTP connection max-lifetime (connTTL ~55s + jitter) so persistent TCP/TLS sockets actually re-resolve rotated ALB IPs.
- Trade-Offs
- Gains predictable p99 latency and fault isolation in exchange for explicit bounding, observability, and slightly higher implementation complexity.
When Fixing Stale DNS Caching in Long-Lived Clients experiences a sudden 5x traffic spike alongside a slow downstream dependency, which engineering choice best protects system stability?
Naive solution (and why Connection: close or TTL=0 fails).
Why this matters: The problem: see what breaks without Naive solution under real concurrency or scale.
Setting Connection: close or networkaddress.cache.ttl=0 trades outages for latency and CoreDNS saturation:
- TLS 1.3 Handshake Tax: Disabling keep-alive adds
~18 msRTT to every single partner call. - CoreDNS Flood: 200 pods resolving uncached DNS on every request blows past the
< 2,000 QPSCoreDNS budget.
Naive solution (and why Connection: close or TTL=0 fails)
Enterprise solution: JVM DNS TTL=30s + Jittered connTTL + NodeLocal DNS.
Why this matters: Operational control: configure bounds, failure handling, and safe production defaults.
Production Java clients combine three coordinated settings:
- 1. Bounded JVM DNS Cache: Set
Security.setProperty('networkaddress.cache.ttl', '30')andnetworkaddress.cache.negative.ttl=5(respecting the 60s ALB TTL). - 2. Jittered Connection Max-Lifetime (
connTTL): Configure Apache HttpClient 5 (TimeValue.ofSeconds(55 + jitter)) or NettyConnectionProvider.maxLifeTime(55s)so persistent TLS sockets recycle gracefully across55–75 s—avoiding synchronized TLS handshake spikes. - 3. NodeLocal DNSCache + Multi-IP Failover: Absorb 200-pod DNS refreshes on-node (
< 1 ms) and enable Happy Eyeballs / retry-on-connect-timeout across multiple returned A-records.
NodeLocal DNS -> JVM Cache (30s) -> Jittered connTTL (55-75s)
1.JVM DNS TTL=30s: Refreshes A-records within half the 60s ALB DNS TTL.
2.Jittered connTTL: Staggers TLS 1.3 reconnects across 55–75s to prevent handshake storms.
3.NodeLocal Cache: Keeps CoreDNS well under the 2,000 QPS external lookup budget.
4.Connect Retry: Safe idempotent retry on ConnectTimeoutException tries next ALB IP.
Coordinating DNS TTL, jittered connection max-lifetime, and NodeLocal DNS achieves <= 60s failover with minimal TLS overhead.
// 1. Bound JVM DNS cache (startup)
java.security.Security.setProperty("networkaddress.cache.ttl", "30");
java.security.Security.setProperty("networkaddress.cache.negative.ttl", "5");
// 2. Apache HttpClient 5 / Netty: bound connection max-lifetime so sockets re-resolve DNS
var connManager = PoolingHttpClientConnectionManagerBuilder.create()
.setDefaultConnectionConfig(ConnectionConfig.custom()
.setConnectTimeout(Timeout.ofMilliseconds(500))
.setTimeToLive(TimeValue.ofSeconds(55 + ThreadLocalRandom.current().nextInt(20))) // jittered
.build())
.setMaxConnPerRoute(100)
.build();
Where DNS & Connection Lifecycle Alignment applies.
Why this matters: Scope boundary: identify where this pattern fits best and where simpler or async alternatives win.
Coordinated DNS + connection-pool TTLs are critical whenever talking to elastic cloud endpoints:
- AWS ALB / NLB & CloudFront Integrations: Following elastic load balancer node scaling without 504s.
- Multi-Region DNS Failover: Ensuring Route53 health-checked failover propagates to long-lived microservices in
< 60 s. - gRPC & HTTP/2 Clients: Combining
MAX_CONNECTION_AGEon servers with client-side DNS re-resolution.
Practice: Make the trade-off yourself.
Why is setting JVM networkaddress.cache.ttl=30 insufficient by itself to rotate traffic away from a decommissioned AWS ALB IP?