Consideration for Long Running Functions
    • Dark
      Light
    • PDF

    Consideration for Long Running Functions

    • Dark
      Light
    • PDF

    Article Summary

    #ServerlessTips - Azure Functions
    Author: Steef-Jan Wiggers Azure MVP

    If you examine the best practices of Azure Functions, the top one listed is avoiding long-running functions.

    Functions are suitable for executing code fast and stateless.

    For instance, you get a message from a service bus and push into a storage blob or Cosmos DB collection. It is easily built using the service bus trigger and Cosmos DB binding.

    using System;
    using System.Threading.Tasks;
    
    public static void Run(string mySbMsg, ILogger log, out object outputDocument)
    {
        log.LogInformation($"C# ServiceBus topic trigger function processed message: {mySbMsg}");
    
        outputDocument = new
            {
                mySbMsg
            };    
    }
    

    Running code for several minutes with a function requires some consideration:

    • When running functions on a consumption plan, the default timeout is five minutes, which you can increase that to ten minutes.
    • Running a function for a considerable time is better suited when running under an App Service Plan or as a WebJob. Both do not have limitations for execution times.
    • When a function has several dependencies than that are loaded - both explicitly and implicitly. A single module loaded by your code may load its additional modules (refer Optimize the performance and reliability of Azure Functions).
    • Long-running functions can be implemented through Azure Durable Functions.

    With Durable Functions you can easily support long-running processes, applying the Async HTTP APIs or Monitoring Patterns. In case you are dealing with functions that require some time to process the payload or request consider running under an App Service Plan, WebJob, or Durable Functions.


    Was this article helpful?