Azure How Many Functions In One Function App

Azure How Many Functions In One Function App

In this Azure tutorial, we will discuss Azure how many functions in one Function App.

Azure how many functions in one function app? One Azure Function App can scale out to a max of 200 instances as per Microsoft.

Azure How Many Functions In One Function App

Well, here we will discuss how many Azure Functions are in One Azure Function App. So, As per Microsoft, By default, The Azure Function App that is under the Consumption plan will scale out to as many as 200 instances.

Similarly, if the Azure Function App is under the Premium plan, it can scale out to a maximum of 100 instances, as per Microsoft.

Again, A single instance inside the Azure Function app can process more than one request. Currently, no limit is set on the number of concurrent executions.

You can set the functionAppScaleLimit property value to set the minimum limit value. You can set the property value to 0 or null to indicate unrestricted.

You can also specify the functionAppScaleLimit value in between 1 to the max limit as per your Azure Plan like 200 for the Consumption plan and 100 for the Premium plan.

Azure Function App Multiple Functions

In the Azure Function world, An Azure Function App can contain multiple individual Azure Functions. If you go a little in-depth, Azure Function App provides the execution context for all the Azure Functions inside the Azure Function App. In that execution context, your function runs.

Note: One important point to note down here is, All the Individual functions inside the Azure Function App must be developed with the same language.

The behavior of the Azure Function App is applied to each Azure Function present inside the Azure Function App. Another essential thing to note here is that All the individual functions inside an Azure Function App share the same resources per instance as the function App scales. Each function inside the Azure Function App is deployed and scaled together.

One more thing to remember is that all the functions inside the Function App share the same pricing plan, runtime version, deployment method, etc. For individual functions, you can define their separate connection string and Application settings for each one.

Multiple Azure Functions In One Class

Yes, You can keep multiple Azure Functions in one class. For example, You can keep the Azure Functions below inside one class.

using System;
using System.IO;
using System.Threading.Tasks;
using Microsoft.AspNetCore.Mvc;
using Microsoft.Azure.WebJobs;
using Microsoft.Azure.WebJobs.Extensions.Http;
using Microsoft.AspNetCore.Http;
using Microsoft.Extensions.Logging;
using Newtonsoft.Json;

namespace MyFunctionApp
{
    public static class Vehicle
    {
        [FunctionName("FunctionAUDI")]
        public static async Task<IActionResult> AUDI(
            [HttpTrigger(AuthorizationLevel.Function, "get", "post", Route = null)] HttpRequest req,
            ILogger log)
        {
            log.LogInformation("FunctionAUDI processed a request.");
            //Add the Business Logic
            string name = req.Query["name"];

            string requestBody = await new StreamReader(req.Body).ReadToEndAsync();
            dynamic data = JsonConvert.DeserializeObject(requestBody);
            name = name ?? data?.name;

            string responseMessage = string.IsNullOrEmpty(name)
                ? "This FunctionAUDI executed successfully. Pass a name in the query string or in the request body for a personalized response."
                : $"Hello, {name}. This FunctionAUDI executed successfully.";

            return new OkObjectResult(responseMessage);
        }

        [FunctionName("FunctionBMW")]
        public static async Task<IActionResult> BMW(
            [HttpTrigger(AuthorizationLevel.Function, "get", "post", Route = null)] HttpRequest req,
            ILogger log)
        {
            log.LogInformation("FunctionBMW processed a request.");
            //Add the Business Logic

            string name = req.Query["name"];

            string requestBody = await new StreamReader(req.Body).ReadToEndAsync();
            dynamic data = JsonConvert.DeserializeObject(requestBody);
            name = name ?? data?.name;

            string responseMessage = string.IsNullOrEmpty(name)
                ? "This FunctionBMW executed successfully. Pass a name in the query string or in the request body for a personalized response."
                : $"Hello, {name}. This FunctionBMW executed successfully.";

            return new OkObjectResult(responseMessage);
        }
        [FunctionName("FunctionSkoda")]
        public static async Task<IActionResult> Skoda(
            [HttpTrigger(AuthorizationLevel.Function, "get", "post", Route = null)] HttpRequest req,
            ILogger log)
        {
            log.LogInformation("FunctionSkoda processed a request.");

            //Add the Business Logic
            string name = req.Query["name"];

            string requestBody = await new StreamReader(req.Body).ReadToEndAsync();
            dynamic data = JsonConvert.DeserializeObject(requestBody);
            name = name ?? data?.name;

            string responseMessage = string.IsNullOrEmpty(name)
                ? "This FunctionSkoda executed successfully. Pass a name in the query string or in the request body for a personalized response."
                : $"Hello, {name}. This FunctionSkoda executed successfully.";

            return new OkObjectResult(responseMessage);
        }
    }
}

You can keep multiple Azure functions in one project like above, but creating a separate Azure Function for each case is recommended instead. You might be thinking now, what if I have some standard code to use across all the Functions? In that case, what you can do is, You can create a standard class and then inject that class into all the Azure Functions.

One more benefit of creating separate Azure Functions is that you can enable/disable/delete one Azure Function whenever you need to, and it will not affect the Other one. So, the risk factor will be less in the Production environment.

Analyzing the logs for the individual Azure Functions will be easier in case of any critical issues. It will also help to monitor individual Azure Functions.

Another very important factor is that when there are independent Azure Functions, It will be really helpful in terms of Maintenance activity. If you have to make any code change, It will not affect the other functions. But when you keep all the Functions inside the same Class file, there is a chance that the code change might also affect the other functions. Especially, in the case of the Production deployment, you should be careful.

Azure Function Parallel Execution

In the Scenario, when more than one triggering event occurs faster than a single-threaded function, The runtime may invoke the Azure Function more than once in parallel. The number of concurrent function invocations depends on the trigger being used inside the Azure Function App.

Long Running Azure Function

Long-running functions run longer than the defined timeout limit. The problem with a Long-Running function is that once it crosses the maximum timeout duration, it can stop at any point in time, and you will not get any output. So, because of this timeout limit, the Azure Function needs to be short, and you should avoid writing the long-running Azure Function.

The maximum time out for the Azure Function is 5 minutes when your Azure Function is under the Consumption plan. Though you can extend it to 10 minutes max, it won’t be enough for the long-running Azure Function, and your Azure function can stop at any point once it reaches the max 10 minutes.

So, to help with these scenarios, the Function Chaining concept comes into the picture where you need to break up the long-running tasks or processes into smaller units that can be chained together. This is executing a set of functions in a particular order. Here, the output of one Azure Function will be the input for the following Azure Function.

You May also like following the articles below

Wrapping Up

Well, in this article, we discussed Azure how many functions in one Function App. I hope You have enjoyed this article !!!