Hello
I am building a Node.js application that connects to a SQL database & it usually works fine until the database connection drops (perhaps due to idle timeout or server restart). After the disconnect; the app tries to reconnect, but this causes the entire application to hang / become unresponsive.
Restarting the process helps temporarily but that’s not a robust solution for a long-running production setup.
I have tried using libraries like node-postgres
with built-in retry options & even implemented a manual reconnect loop but I still face long delays or blocked event loops during reconnection attempts.
I wonder if using pattern like exponential backoff, connection pooling / streaming reconnections can help. I would love to know best practices / patterns that seasoned developers use to handle this more gracefully. Checked mysql - Managing database connections in Node.js, best practices? - Stack Overflow guide for reference. I was also wondering what is a DevOps Engineer supposed to handle in cases like this?
If anyone has experience handling these cases especially in production-grade Node.js services I would appreciate examples / advice. It’s crucial to keep the app responsive even during temporary database outages.
Thank you !!