I am now using Polly in production and it works awesomely. I followed the same fault handling policy noted on Hanselman’s blog about Polly.
var policy = Policy .Handle<SqlException>() .WaitAndRetry(5, retryAttempt => TimeSpan.FromSeconds(Math.Pow(2, retryAttempt)), (exception, span) => { // Log transient error } );
This is a decidedly easy way to implement an exponential back-off retry policy. On the first retry it waits 2 seconds, by the 5th and final retry it will wait 32 seconds. This means this sql call will wait up to 1 minute for attempting to complete the sql call (ignoring any time spent executing the sql call prior to a sql exception being raised)
real world production code using Polly ? good patterns and practices ?
The most important ‘pattern’ with Polly is ensuring that you don’t retry anything that has retries. That can cause a cascade of waiting seconds or even minutes of delay. Yes i’ve used Polly in production inconjuction with Dapper & SQLConnection, if any of my reads would error due to cloud-stuff or just load issues, it would immediately retry. I use the exponentional back off strategy 1s, 2s, 4s, 16s, 32s (2^Nth retry)