If you get a timeout from your database, it is not very likely that it will respond in a timely manner a few milliseconds later.
Repeated attempt in a compressed cycle, in your opinion, is likely to make the situation worse , because you will put excessive load on the database server, as well as bind the thread in the calling code.It would be safer to enter a timeout between each attempt.
For more complex scenarios, you might think of a progressive wait pattern in which you try again more often at the beginning, and then at longer and longer intervals if you still have timeouts.
You can also look into the Circuit Breaker design template from Release It! , as well as many other patterns and anti-patterns described in this book.
The status template is suitable for implementing a circuit breaker.
source share