Search code examples
azure-functionsazure-function-async

Are there benefits to an async function?


Azure functions allows me to write C#/F# (and more) functions which are executed given certain conditions. These functions can be async (by returning a Task).

The cool thing about azure functions is that they automatically scale up depending on load. One of the cool things about the async/await pattern on a "classic" server, is that you can better utilize the cores so you can handle more requests.

Since azure functions automagically scales, are there any benefits for me to write async functions?


Solution

  • You'd use async in Azure Functions for the same reasons you would in any other application. For operations that block on potentially long running external I/O, it'll be a much more efficient use of resources. Azure Functions fully supports async in the runtime core, so when used correctly, it will allow for more parallelism and better throughput on a single Function App since threads aren't blocked waiting for I/O and can be used to process more requests/triggers.

    If your Function App is running on a Classic SKU, then you're paying for an Always On instance, so it's clear you want to use resources as efficiently as possible.

    When running in the Dynamic SKU, I think your question was that if we'll just scale out your functions as needed, then who cares if they're using resources efficiently? I'd still say that it is best for you to code your functions so they run as efficiently as possible. That way we're only scaling you out when truly needed, and minimizing any cold start times for new instances as we spin them up.