I worked with countless apps and developers at Heroku on getting their apps running well on the platform. There was always one great mystery: why not build our apps a bit differently (dare I say better) to work in the cloud?
The database connection pattern is spot on. For any network resource, try to connect and if there is a problem retry with back off.
Also log the connection error events that a monitoring tool can notify off of.
I've seen apps that have the absolute worst behavior around this error that will happen. The worst is crashing the app in a way that triggers thrashing around restarts.
We had to build tons of complex restart back off logic into the Heroku platform to handle this.
I often wish app frameworks made this easier. I think most devs don't do these things because it is a chore for s problem that only happens occasionally.
But what if Rails baked this into ActiveRecord?
At one point Rails only logged to files on disk. We came together to add stdout logging to the framework.