How would you rotate a database password without downtime?

IntermediateScenarioDatabase connections in apps
Answer

Short answer

Use a two-credential (dual-user or dual-password) approach: create the new credential while the old one still works, roll the new value out to all app instances, confirm nobody uses the old one, then revoke it. Managed tools like AWS Secrets Manager rotation automate this with alternating users.

Manual steps

  1. Create the new password (or a second user orders_app_b with the same grants).
  2. Update the secret in the vault → External Secrets syncs the K8s Secret.
  3. Roll the pods (kubectl rollout restart deploy/orders or a tool like Stakater Reloader) so they pick up the new value; pools reconnect with the new credentials.
  4. Verify all connections use the new credential (pg_stat_activity / SHOW PROCESSLIST by user).
  5. Revoke the old password/user.

Automated

AWS Secrets Manager rotation Lambda (alternating-users strategy) switches between two DB users, so one is always valid; apps that read the secret on each new connection never see an outage.

Common failure

Changing the password directly on the database first → every pod with the old password fails immediately. Always make the new one valid before removing the old.

What to say in the interview

"Overlap the credentials: create the new one, update the vault, roll pods via External Secrets and a reloader, verify sessions moved over, then revoke the old one. Secrets Manager's alternating-users rotation automates exactly this."

All Build Tools (Java, Node.js, Python, .NET) questions Roadmap: Connecting apps to databases

More on Database connections in apps