Featured image of post Durable Functions: Retry Logic Can Save You Money

Durable Functions: Retry Logic Can Save You Money

TLDR

If immediate action is not a hard requirement, you can address service unavailability by implementing retry logic when consuming endpoints that do not guarantee availability.

Context

Azure Service Bus is a powerful tool for decoupling applications, especially in microservices architectures. However, choosing the correct tier can be challenging due to significant pricing differences. The Standard tier is cost-effective but can be unstable, while the Premium tier offers excellent availability at a much higher cost.

If availability is important but you can tolerate occasional latency, Durable Functions can help by implementing retry logic. This ensures that messages are sent even if the Service Bus is temporarily unavailable.

Example Code

1
2
3
4
5
6
7
8
9
var options = TaskOptions.FromRetryPolicy(new RetryPolicy(
    maxNumberOfAttempts: 20,
    firstRetryInterval: TimeSpan.FromSeconds(5),
    backoffCoefficient: 3,
    maxRetryInterval: TimeSpan.FromMinutes(1)
));

await context.CallActivityAsync<ActivityFunctionResponse>(
    nameof(ServiceBus.SendMessageToServiceBus), args, options);

In this example:

  • The orchestrator retries up to 20 times.
  • The first retry occurs after 5 seconds.
  • The retry interval triples with each attempt, up to a maximum of 1 minute.

This approach ensures reliable message delivery while using the cost-effective Standard tier.

All rights reserved
Built with Hugo
Theme Stack designed by Jimmy