After an RDS Multi-AZ failover, the database is healthy within 2 minutes but the Java app keeps failing for 20 minutes. Why, and how do you fix it?
IntermediateScenarioData and databases
Answer
Situation read → The failover changes which IP the RDS endpoint points to. The app is still talking to the old IP, either because of DNS caching or because of stale pooled connections.
What I'd do →
- Check JVM DNS caching: with a security manager or certain settings it caches forever. Set a short TTL:
# $JAVA_HOME/conf/security/java.security
networkaddress.cache.ttl=5
- Configure the connection pool to validate and recycle: HikariCP
maxLifetimeunder a few minutes,keepaliveTime, and a connection timeout so broken connections fail fast. - Use a driver that understands failover (the AWS Advanced JDBC Wrapper) or put RDS Proxy in front, which keeps app connections and handles the switch.
- Test it: trigger failover in staging and measure app recovery.
aws rds reboot-db-instance --db-instance-identifier staging-db --force-failover
Why → Database failover is only as fast as the client's ability to notice and reconnect.
Interview tip → Say "test failover with --force-failover"; most teams only find this during a real one.
More on Data and databases
A release needs to rename a column that the running app reads and writes. How do you do it with zero downtime?IntermediateHow do you prove your database backups actually work?IntermediateDesign backups for an RDS PostgreSQL database with RPO of 5 minutes and RTO of 1 hour, including a region failure.AdvancedYour migrations run in an init container and two pods ran them at the same time during a deploy, leaving the schema half-applied. How do you fix the approach?IntermediateUpgrade RDS PostgreSQL from 13 to 17 with minimal downtime. How?AdvancedYou need to add an index and a column to a 500-million-row table that's written to constantly. How do you avoid locking it?Advanced