“Singleton” Azure Functions

Azure Function Logo

This is not the sort of “stuff” I would usually be writing about in the past. Lately, though, more and more work that I am involved with is somewhat related to Azure. More often than not, my daily tasks include bending Azure services to my needs rather than writing code (which is a tediously philosophical discussion in itself!).

In one of our current projects, the architecture requires a number of “singleton” services to be connected to a shared service bus and regularly communicate with “other services“. In Azure terminology those singleton services would qualify as Web Jobs. Due to the current direction Microsoft is taking in regards to Azure Functions, we have decided to go with them, rather than Web Jobs (not to mention it is much easier to deploy and monitor). All good and well so far, excluding a few annoyances here and there due to immature management Web UI.

One of the peculiar things that took some time to figure out, was how to set up a function to run as a singleton. It can be annoying to find exactly what needs to be done in tons of promotional material and blogs all focusing on the “benefits of scaling out“. In the unlikely event you’re trying to make sure your function app runs as singleton try the following:

  1. Set up your function app using the App Service plan. Consumption plan gives Azure infrastructure all the power to move your app between machines or start up additional instances.
  2. Make sure the “Always On” is toggled in Application Settings. Our singleton needs to be up an running at all times:Azure Function Always On
  3. Finally, one has to add WEBSITE_MAX_DYNAMIC_APPLICATION_SCALE_OUT with a value of “1” to the Application Settings. Do not askAzure Function Scaleout Setting

Be aware, that using an App Service plan incurs additional costs, but I guess that is not different compared to attaching Seb Jobs to existing Web Applications.