/
Retry Pattern

Retry Pattern

Problem

  • Faults include the momentary loss of network connectivity to components and services, the temporary unavailability of a service, or timeouts that occur when a service is busy.

  • Faults are typically self-correcting, and if the action that triggered a fault is repeated after a suitable delay

 

Solution

  • Introduce a retry mechanism to minimize the impact on the performance.

  • There are a lot of Azure resources capable of helping to implement a retry pattern even though we know that we should do it in the code :

→ Azure Service Bus; Azure Functions; Azure API Management; Azure Cosmos DB.

→ In the code, we use the .NET Library

image-20240829-184532.png

Retry In Practice

// Provide the client configuration options for connecting to Azure Blob Storage BlobClientOptions blobOptions = new BlobClientOptions() { Retry = { Delay = TimeSpan.FromSeconds(2), MaxRetries = 5, Mode = RetryMode.Exponential, MaxDelay = TimeSpan.FromSeconds(10), NetworkTimeout = TimeSpan.FromSeconds(100) }, }; BlobServiceClient blobServiceClient = new BlobServiceClient(accountUri, new DefaultAzureCredential(), blobOptions);