How do you rotate database credentials without taking the app down?
Our app has used the same database password since launch, which I know is bad. I want to start rotating it, but the obvious approach (change password, update config, restart) has a window where things break.
The pattern I've read about is to create a second user, deploy with the new credentials, confirm everything's connected, then remove the old one. Does that hold up in practice?
How do you handle rotation, especially if you have background workers or cron jobs that hold connections for a long time?
Comments · 4
Use two valid credentials at once. Add the new password, deploy it, then remove the old one. That way nothing breaks during the swap.
Move it into a secrets manager first, so the app reads the password at startup. Then rotation becomes a config change instead of a code change.
Do connections from a long-running app keep using the old password until they reconnect? How do you handle that?
Yes, existing connections stay valid until they close. Set a max connection lifetime so the pool refreshes and picks up the new credential.