Azure Function / Durable best practice

Kyle K 21 Reputation points
2020-12-09T16:20:22.07+00:00

Hi all,

I am wondering if someone could guide me on if this is acceptable to have in a azure function and if so, would a durable function be more appropriate.

I am writing a function that will have a Service Bus trigger to take messages off the queue.

Within this function, I would ideally like to make three sequential API calls, given the response the flow either continues to the next or discountues.

If this could be a durable function, each call needs to be in order and the result of each call determines if the next should be called at all.

I am trying to decide if code like this is appropriate or not for this.

Thanks.

Azure Functions
Azure Functions
An Azure service that provides an event-driven serverless compute platform.
4,605 questions
0 comments No comments
{count} votes

Accepted answer
  1. Josh Carlisle 86 Reputation points MVP
    2020-12-09T17:42:17.15+00:00

    From a high level, I don't see any reason why this use-case\workflow wouldn't be a good fit for Durable Functions assuming that what is going on in those functions is doing async\long running activities that benefit from Durable Functions. Function Chaining/Sequence is a core feature and you can find some more details at https://learn.microsoft.com/en-us/azure/azure-functions/durable/durable-functions-sequence. You can use the results from each step to determine the next.

    If the APIs that you are referring to are HTTP\REST based APIs there are some additional features that are useful that simplify the solution a good deal (see https://learn.microsoft.com/en-us/azure/azure-functions/durable/durable-functions-http-features?tabs=csharp#consuming-http-apis).

    One word of caution is that the results of your functions do need to be deterministic because of how Durable Functions are essentially replays the entire workflow for each step. More details at https://learn.microsoft.com/en-us/azure/azure-functions/durable/durable-functions-code-constraints.

    2 people found this answer helpful.
    0 comments No comments

2 additional answers

Sort by: Most helpful
  1. Jaliya Udagedara 2,821 Reputation points MVP
    2020-12-10T18:18:53.87+00:00

    Yes, One rule of thumb related to Azure Functions are, we should avoid long-running tasks (see the Function app timeout duration.

    But as you suggested and as @Josh Carlisle mentioned above, you can use a durable function if you think these calls can take a longer time. Durable functions are meant for long-running tasks. (they won't run long, they will sleep/awake as needed and handle the long run). And again as @Josh Carlisle mentioned, you can use the Function Chaining pattern where you can do things like passing the output of the first call to the second call, etc.

    Please let us know if you have any questions.

    1 person found this answer helpful.
    0 comments No comments

  2. Kyle K 21 Reputation points
    2020-12-10T10:52:20.493+00:00

    Hello,

    Thank you for your reply.

    It would be three REST calls out to third party endpoints.

    I cannot seem to determine if Azure functions in their own right would be ok to handle this since they aren't meant to be long running and would need the response from each within a few seconds SLA.

    The final call would require some business logic to determine the final API calls data so could be a few lines of logic.

    I just want to ensure I am not misunderstand the purpose of Azure functions and putting too much functionality into them.

    Is there a rule or best practice?

    3x API calls, which the final API call requiring some logical interpretation of the data to send a final JSON body.
    Is this code sounding like it should reside in a normal application?

    Thank you.

    0 comments No comments