Azure Function App Multiple Functions

The most powerful feature of Azure Functions is the ability to host multiple functions within a single Function App. This approach can significantly reduce your operational costs while simplifying your architecture. In this comprehensive guide, I’ll explain everything you need to know about deploying and managing multiple functions within a single Azure Function App.

Azure Function App Multiple Functions

You can consider the Azure Function App as a container for one or more Azure Functions. You can host one or more Azure functions inside one Azure Function App. If you have different Azure Functions with different languages, you can also keep them inside one Azure Function App.

Keeping multiple Azure Functions together within one Azure Function App depends on several factors, including memory consumption and workload requirements.

For example, if all the Azure functions inside the Azure Function App have almost the same workload and are consuming memory within the maximum limit of memory allocated to that particular Azure Function App in total, then you can keep them inside one Azure Function App.

But, say you have multiple Azure Functions inside the Azure Function App. One among them is running with a high workload; in that case, it is better to separate that Azure Function into a separate Azure Function App, and the others you can keep on the first Azure Function App.

Why Host Multiple Functions in a Single Function App?

Here’s why consolidating multiple functions into a single Function App

Cost Efficiency

  • Each Function App incurs its own hosting costs
  • Shared compute resources across functions
  • Reduced storage account requirements

Simplified Management

  • Single deployment pipeline
  • Unified monitoring and logging
  • Centralized configuration management

Improved Performance

  • Reduced cold start times between related functions
  • Shared memory space for common dependencies
  • More efficient resource utilization

Methods to Create Multiple Functions in a Single Function App

There are several approaches to organizing multiple functions within a single Function App. Let’s explore each one.

Method 1: Using Visual Studio for Multiple Functions

Visual Studio provides an excellent development experience for Azure Functions. Here’s how to set up multiple functions in a single project:

  1. Create a new Azure Function App project in Visual Studio
  2. Right-click on the project in Solution Explorer
  3. Select Add > New Azure Function
  4. Configure each function with its own trigger type

Each function will have its own class file, but will be deployed to the same Function App when published.

Method 2: Using Azure CLI and Function Core Tools

If you prefer a command-line approach, you can use the Azure CLI and Function Core Tools to create and manage multiple functions:

# Initialize a function project once
func init --worker-runtime python --model V2

# Create your first function
func new --name function1 --template "HTTP trigger"

# Create your second function
func new --name function2 --template "Timer trigger"

# Deploy all functions to a single Function App
func azure functionapp publish myFunctionAppName

Method 3: Multiple Functions in the Same File

For simplicity and specific use cases, you can even create multiple Azure Functions in the same file. This approach works well when:

  • Functions share common logic
  • You want to reduce the file count
  • Functions are closely related

Here’s a simple example using C#:

// First function in the file
[FunctionName("Function1")]
public static async Task<IActionResult> Function1(
    [HttpTrigger(AuthorizationLevel.Function, "get", "post", Route = null)] HttpRequest req,
    ILogger log)
{
    log.LogInformation("Function1 processed a request.");
    return new OkObjectResult("Hello from Function1");
}

// Second function in the same file
[FunctionName("Function2")]
public static async Task<IActionResult> Function2(
    [HttpTrigger(AuthorizationLevel.Function, "get", "post", Route = null)] HttpRequest req,
    ILogger log)
{
    log.LogInformation("Function2 processed a request.");
    return new OkObjectResult("Hello from Function2");
}

Best Practices

Below are the best practices to keep in mind.

Organize by Domain

Group functions that belong to the same domain or business capability. For example, all functions related to order processing should live in the same Function App.

Consider Resource Requirements

Functions with similar resource requirements should be grouped together. Don’t mix resource-intensive functions with lightweight ones, as this can lead to resource contention.

Plan Your Routes Carefully

When creating multiple HTTP-triggered functions, carefully plan your route patterns. As mentioned in Microsoft’s documentation, you can set up distinct routes like:

  • api/automation1
  • api/automation2

This allows each function to be called individually while still residing in the same Function App.

Shared Configuration

Leverage application settings at the Function App level for shared configuration:

{
  "IsEncrypted": false,
  "Values": {
    "AzureWebJobsStorage": "DefaultEndpointsProtocol=https;AccountName=...",
    "FUNCTIONS_WORKER_RUNTIME": "dotnet",
    "SharedSecret": "this-is-shared-across-all-functions",
    "Function1Setting": "specific-to-function-1",
    "Function2Setting": "specific-to-function-2"
  }
}

Step-by-Step Tutorial: Deploying Multiple Functions to a Single Function App

Let’s walk through a complete example of creating and deploying multiple functions to a single Function App:

Prerequisites:

1. Create a New Function App Project

# Create a new directory
mkdir MultipleAzureFunctions
cd MultipleAzureFunctions

# Initialize a new function project
func init --worker-runtime dotnet --model V2

2. Add Multiple Functions

# Add first function - HTTP trigger
func new --name OrderProcessing --template "HTTP trigger"

# Add second function - Timer trigger
func new --name DailyReporting --template "Timer trigger"

# Add third function - Queue trigger
func new --name NotificationHandler --template "Queue trigger"

3. Configure Individual Function Routes

For HTTP-triggered functions, modify the function.json file (or attributes in C#) to specify unique routes:

{
  "bindings": [
    {
      "authLevel": "function",
      "name": "req",
      "type": "httpTrigger",
      "direction": "in",
      "route": "orders/process",
      "methods": ["post"]
    },
    {
      "name": "$return",
      "type": "http",
      "direction": "out"
    }
  ]
}

4. Share Code Between Functions

Create a shared class library for standard functionality:

// Shared.cs
public static class Shared
{
    public static string FormatResponse(string message)
    {
        return $"Response: {message} - Generated at {DateTime.UtcNow}";
    }
    
    public static bool ValidateInput(string input)
    {
        return !string.IsNullOrEmpty(input);
    }
}

5. Deploy to Azure

# Create Function App in Azure (if not already created)
az functionapp create --resource-group MyResourceGroup \
                      --consumption-plan-location eastus \
                      --runtime dotnet \
                      --functions-version 4 \
                      --name MyMultiFunctionApp \
                      --storage-account mystorageaccount

# Deploy all functions at once
func azure functionapp publish MyMultiFunctionApp

Performance Monitoring

When hosting multiple functions in a single Function App, monitoring becomes even more critical. Set up Application Insights to track:

MetricWhat to WatchTypical Threshold
Memory UsageOverall consumption<80% of allocated memory
Execution DurationPer function<75% of the timeout setting
Concurrent ExecutionsOverall loadVaries by plan type
Cold Start FrequencyStartup delays<5% of invocations

Conclusion

Hosting multiple functions within a single Azure Function App offers significant advantages in terms of cost, management, and performance. By following the best practices and examples mentioned in this article, you’ll be well-equipped to design efficient functions on Azure.

You may also like the following articles below

Azure Virtual Machine

DOWNLOAD FREE AZURE VIRTUAL MACHINE PDF

Download our free 25+ page Azure Virtual Machine guide and master cloud deployment today!