50

Where can I find guidance on organizing a Visual Studio solution with multiple Azure Functions? Specifically, how should the project be organized?

A single Azure Function resides in a single class file. I suppose each function could be its own class file, all stored within a single project. But is this the optimal solution or do I risk future complications due to a poorly organized project / solution?

Janusz Nowak
  • 2,595
  • 1
  • 17
  • 36
DenaliHardtail
  • 27,362
  • 56
  • 154
  • 233
  • 1
    You can also put multiple functions into the same static class if you wish. That's your choice, and if you find issues - you are free to change it at any time. – Mikhail Shilkov Sep 01 '17 at 05:14
  • Another useful Stackoverflow answer on [Multiple Function Apps with fewer functions **VS** Few Function Apps with many funtions](https://stackoverflow.com/questions/40877236) – Emil Aug 14 '19 at 10:51
  • 1
    Maybe a bit late but...from the official documentation https://learn.microsoft.com/en-us/azure/azure-functions/performance-reliability#function-organization-best-practices – osotorrio Feb 22 '22 at 22:43

2 Answers2

58

The MS Azure team will probably have a better answer but this is what has worked for us so far.

  • We have several function apps, each are in their own project (and solution).
  • Of those function apps, some have only a single function, others have multiple functions each in their own class/file.
  • Where we have multiple functions, it is because those functions are all related to a particular feature area of our system. Hence they work together, and for us it makes sense to maintain and deploy them as a group.
  • Other function apps are independent, containing only a single function doing a job unrelated to any other function. E.g. we have one timer driven function that crunches some numbers and sends a push notification as required.
  • Grouping the functions in this way has (so far) made sense for us as it gives us a balance between keeping our deployment relatively simple and being able to scale the 'groups' independently.

Anyway this has proved good enough for our project thus far, but I'd be interested to see if there are better ways.

Garth Mason
  • 7,611
  • 3
  • 30
  • 39
  • 2
    One thing I wasn't clear on from your answer - are all of these function apps (in separate projects/solutions) published to the same Azure Functions instance? Or does each solution get its own Azure Functions instance? – Tim Sep 19 '17 at 16:55
  • @Tim - it's the latter. We have a handful of solutions, each with a single project in it -> which gets deployed to a function app. – Garth Mason Sep 20 '17 at 00:14
  • How does this look in terms of the VCS repo? Assuming Git, do you have all the solutions in a single git repo - or does each solution have its own repo? – bbqchickenrobot Apr 17 '18 at 00:13
  • In our case we had them all in a single repo – Garth Mason Apr 17 '18 at 00:36
  • 2
    Hi Garth: if all your functions are in a single repo - how do you deploy them individually if only a single functions changes? Or do they all get deployed with CI/CD when any code in the whole repo changes? – Rodney Jul 11 '18 at 22:40
  • I think from memory we had multiple builds setup, one tied to each solution so we would build/deploy the function app individually. Sorry I don't have access to that code base anymore so I can't look it up :-( – Garth Mason Jul 12 '18 at 00:45
  • 3
    If you put multiple Azure Functions in a single git repo, and deploy using automated CI/CD when new code is committed to your target branch, then all enclosed functions get updated at the same time. If using a Github account with a limited number of private repos, you may not want a repo-per-function solution. But IMHO it's best to organize based on grouping together like functions (with like environment variables or secrets) as the answerer recommended, and also to take into account the minimization of downtime of critical functions due to deployments. – Larry Silverman Jan 30 '19 at 16:04
1

I am also considering having a large solution with many functions deployed as a single unit. As much research I came across the undocumented setting FunctionsInDependencies which can be added to your startup project as below.

<Project Sdk="Microsoft.NET.Sdk">
  <PropertyGroup>
    <TargetFramework>net6.0</TargetFramework>
    <AzureFunctionsVersion>v4</AzureFunctionsVersion>
    <FunctionsInDependencies>true</FunctionsInDependencies>
  </PropertyGroup>

You also need to have a reference in your startup project to the projects that implement function app - e.g. a dummy class inheritance. Otherwise the project reference will be ignored.

This isn't very pretty to be honest. My final call will probably be to declare all the functions and bindings into the startup project and reference the implementation located in sub-projects.

Useful article: https://cosmin-vladutu.medium.com/how-to-split-up-durable-functions-in-multiple-class-projects-328b0015ed37

Guillaume
  • 91
  • 5