How To Organize Azure Functions

How To Organize Azure Functions

In this Azure tutorial, we will discuss How To Organize Azure Functions. Along with this, we will also discuss a few other topics What are Limitations Of Azure Functions, Limitations Of Azure Functions In terms Of Service, Azure Function App Multiple Functions, and Azure Function Folder Structure.

How To Organize Azure Functions? There are multiple ways to organize Azure Functions. Few key ways are as below

  • Organize Azure Functions Based On Your Business Domain
  • Keep the Highly use Functions in its Own Function App
  • Make sure to Keep the related Functions together in a Function App
  • Keep the functions based on their category of usages
  • Don’t Deploy different versions of Azure Functions together.
  • Group the Azure Functions together based on the Trigger Event Category

Below we will discuss in detail for each of the category mentioned here.

How To Organize Azure Functions

Well, here we will discuss a very important topic. As we know the importance of the Azure Functions. We will have to create many Azure Functions as part of our requirements. But the main thing here is, we should know How to organize the Azure Functions.

Organize Azure Functions Based On Your Business Domain

You should organize your Azure Functions Based on your Business domain requirement. We will get a better understanding if we will take an example. For example, if you will consider a travel agency. They have two departments one is Cab booking and another department is Support and maintenance.

The travel agency is using a set of serverless Azure functions to automate their Cab Booking Process and Another set of Azure Functions to automate their support and maintenance part.

You should keep all the Azure Functions related to the Cab booking in the Cab booking Azure Function App and then you should keep the set of Azure Functions related to the support and maintenance in the Support function App.

How To Organize Azure Functions

Keep the Highly use Functions in its Own Function App

This is another very important strategy that means Always keep the highly use Azure functions or those Azure functions that usage is more in their own Azure Function Apps. Because if you will keep a few less usage Azure functions with a high use Azure function then there is a chance that all the functions will scale more CPU usage and memory usage unnecessarily.

This is the reason if you will keep the high usage function in its own Azure Function App then it will only scale the components that need additional resources and memory usage. This is an excellent idea. The only trick here is to identify the highly use Azure Function that you can catch easily.

Make sure to Keep the related Functions together in a Function App

Another idea is to keep the related Azure Functions together in an Azure Function App. Because keeping some unrelated Azure Functions together in an Azure function App is a very bad idea.

If you will consider the Consumption-based plans, as per the plan there is a very minimal difference between the scenario where seven function apps containing a single function and the One function app containing seven functions. The charges you will get based on the invocations of the functions.

In certain scenarios, there is a chance that both the Azure Functions belong together, But still, considering the performance Prospective, you should keep the functions in separate function apps. This is when you are considering the performance of the Azure Function as the key.

Keep the functions based on their category of usages

Another strategy is As an organization, you will have to work with many Azure Functions and it is quite difficult to find out in case you are looking for any specific one and that one might be very similar to the others. In this type of scenario if you will keep the Azure functions together based on their category of usages then it will be very much easy for you as an organization to pool out in case you need any specific for maybe any enhancements or changes.

Don’t Deploy different versions of Azure Functions together

If you are not very sure about the versions of different Azure functions then don’t keep them all together inside one Azure Function App. In case of any exceptions, or if you want to add any package then it will create a lot of issues in case the versions are different.

The maintenance and patching will be easier in case if you will keep the same versions of Azure functions together inside an Azure function App.

Well, these are few key ways to organize the Azure Functions together. This is How To Organize Azure Functions.

Group the Azure Functions together based on the Trigger Event Category

It’s a good idea to keep all the Azure Functions together based on the trigger Event category meaning if you have some HTTP triggered Azure functions. Then keep that HTTP triggered Azure Functions in one Azure Function App.

This strategy will help you with easier maintenance. If you want to do any code changes or in case any DNS update activities as a whole, It will make your job easier in these scenarios.

I personally came across this scenarios and this strategy really helps you a lot, and makes your task easier.

Note: It is always suggested to keep a few related Azure Functions inside the Azure Function App considering the performance and low-risk factor.

Azure Functions Limitations

We know there are many benefits to Azure functions. With its server-less feature, it really helps to automate many tasks without taking any headache for the infrastructure. It makes the developer task easier, Developer just needs to concentrate on the coding part.

What are Limitations Of Azure Functions

With a lot of advantages with Azure Function, there are few limitations with the Azure Functions that need attention as well. Those are as below.

In Case Of Long Running Applications

Azure Functions are not completely suitable for the scenario when there is a long-running operation for you. We know there is an option for the durable function but it won’t satisfy your complete requirement. But it really works like a Champ for a short and quick solution with very few lines of code.

Azure Function runtime version V1 was not that great But the Version V2 is better than version V1.

Integration with third party dlls

Azure functions are not that much comfortable when you have to integrate or refer to the third-party DLLs. It’s quite difficult. it’s not that easy integration with the third-party DLLs.

Limitations Of Azure Functions In terms Of Service

Time out duration

If we will consider the time out duration for the Azure Functions, For Consumption plan, by default it is 5 minutes and Max you can set it to 10 minutes with some additional configurations. For the premium plan it is 30 minutes and you can set it to unlimited with few configurations and For App Service Plan, by default, it is 900 and again you can set the maximum to unlimited, But you need to pay more for the App Service plan and Premium Plan.

Max Number Of instances

The maximum number of instances, for the Consumption plan, is 200, For the premium plan, it is 20 whereas for the App service plan it is 10 to 20 max.

Max Request Size

The max size for the Request is 100 MB in the case of Consumption, Premium and App service plan.

Storage Size

In case of the storage size, for the Consumption plan, it is 1 GB, For the Premium plan, it is 250 GB and In case of the App Service Plan, it is 500 to 1000 GB.

Number Of App Service plans

In the case of App Service plans, for the consumption plan, it is 100 per region, For the premium plan, it is 100 per resource group and For the App service plan, it is 100 per resource group.

These are a few limitations in the case of Azure Functions that you need to keep in your mind before deciding to go with the Azure Functions.

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 will have different Azure Functions with different languages, you can also keep them inside one Azure Function App.

Keeping multiple Azure Functions together inside one Azure Function App depends on many factors like memory consumption, workloads, etc. For example, if all the Azure functions inside the Azure Function App have almost the same workload and all the Azure Functions are consuming the 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 on it, then, in that case, it is better to separate that Azure Function to a separate Azure Function App and the others you can keep on the first Azure Function App.

There is no specific rule document that you should follow while keeping the Azure Functions in different Azure Function Apps, It’s all about your analysis and your solution architecture and it purely depends on your requirements as well.

Azure Function Folder Structure

Well, here we will discuss the Azure Function Folder Structure. You should understand it before you start the development of the Azure Functions.

Once, you will create an Azure Function Project using Visual Studio 2019, You will get the below Azure Function Project Structure.

Azure Function Folder Structure

If you will click on the Project name i.e TestAzureFunction in my case, that is the  .csproj file that contains all the configurations for your Azure Function project. This file contains the code as below

<Project Sdk="Microsoft.NET.Sdk">
  <PropertyGroup>
    <TargetFramework>netcoreapp2.1</TargetFramework>
    <AzureFunctionsVersion>v2</AzureFunctionsVersion>
  </PropertyGroup>
  <ItemGroup>
    <PackageReference Include="Microsoft.NET.Sdk.Functions" Version="1.0.36" />
  </ItemGroup>
  <ItemGroup>
    <None Update="host.json">
      <CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
    </None>
    <None Update="local.settings.json">
      <CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
      <CopyToPublishDirectory>Never</CopyToPublishDirectory>
    </None>
  </ItemGroup>
</Project>

Dependencies contain all the packages(DLLs) and SDKs needed for your Azure Function Project. You will expand that you can able to see many dlls that are referred to your Azure Function Project. Below are few of them

Microsoft.NET.Sdk.Functions
Microsoft.Azure.Webjobs
NewtonSoft.json

Function1.cs file is the main class file that contains the Azure Function code. If you want to modify the Azure Function logic based on your business requirement then you need to modify the Azure function code in this file.

The file will look like below

Azure Function Folder Structure visual studio

The next file is the host.json file contains all the settings or configuration options that affect all the Azure functions within that Azure function App. If you want to apply any configuration property changes then this is the file where you will have to change.

The default host.json file contains the below code

{
    "version": "2.0",
    "logging": {
        "applicationInsights": {
            "samplingSettings": {
                "isEnabled": true,
                "excludedTypes": "Request"
            }
        }
    }
}

Next, coming to the local.settings.json file, you can keep the application settings value that we get from the Azure Portal. It contains the configurations like below

{
    "IsEncrypted": false,
    "Values": {
        "AzureWebJobsStorage": "UseDevelopmentStorage=true",
        "FUNCTIONS_WORKER_RUNTIME": "dotnet"
    }
}

One important thing to note down here is, local.settings.json file changes are for the local use only, you can consider it for the development purpose only. Once you will deploy the Azure Function to Azure. You will not get the reference for this file. This is very important to remember.

If you are referring any of the application settings from the local.settings.json file then Once you will deploy the Azure Function to the Azure Portal, Make sure to do the same application settings changes manually in the Azure Portal since you will not get the reference of this file in Azure or else your Azure Function will not work properly.

You may also like following the below Articles

Wrapping Up

Well, in this article, we discussed, How To Organize Azure Functions. Along with this, we will also discuss a few other topics What are Limitations Of Azure Functions, Limitations Of Azure Functions In terms Of Service, Azure Function App Multiple Functions, and Azure Function Folder Structure. Hope you enjoyed this article !!!