Multiple durable functions in one function app

Viewed 792

Is it possible to host multiple durable functions in one function app? How can we specify a different task hub name for each durable function?

2 Answers

No, don't try to host more than one Durable Function in the same Function App. Under the hood, Durable Functions use storage resources for orchestration. These storage queues and tables are managed automatically for you and they exist within a storage account. So far, so simple.

If multiple Durable Functions are to share the same storage account, each needs it's own set of storage resources, so a "task hub name" is used by the runtime to identify which storage resources to use for each durable function.

If two Durable Functions share the same storage resources, strange things will happen and neither of your functions will work. The runtime will be routing trigger events to either function seemingly randomly, leaving most orchestrations in a pending or running state and never completing.

The default for the task hub name is based on the name of the function app, but it can be overridden in the host.json file

{
  "version": "2.0",
  "extensions": {
    "durableTask": {
      "hubName": "CustomTaskHubName"
    }
  }
}

Here is the problem: a Function App can have only one task hubName configured, which means, each durable function needs to be hosted in its own Function App, with its own deployment pipeline and possibly its own code repository etc, depending on your setup.

Also, There is a TaskHub property on the DurableClient Attribute, which would suggest that you could have multiple task hub names within the same app. However, the documentation is unclear in this regard and I haven't been able to get it work after a lot of attempts. From what I can tell, this is purely for pulling the configuration out of appsettings to make it easier to vary the task hub name between development, testing and production environments. It would be great if I am wrong on this.

Adding to Daniel Dyson's response:

"If multiple function apps share a storage account, each function app must be configured with a separate task hub name. A storage account can contain multiple task hubs. This restriction generally applies to other storage providers as well."

As per Microsoft docs, you can have multiple durable functions within a single function app so long as you ensure the task hub names are different.

Source: https://docs.microsoft.com/en-us/azure/azure-functions/durable/durable-functions-task-hubs?tabs=csharp

Related