3

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?

adelb
  • 791
  • 7
  • 26
  • Yes, it's possible to host multiple durable functions in one function app. Any specific need to specify to have different task hub for each durable function? – user1672994 Jan 29 '21 at 15:45
  • If one durable function has more load that the other, I assume the performance of the lighter function might be impacted by the amount of historical rows that the heavier function creates. Also for trouble shooting I think it will be easier to browse each history separately. I haven't found a way to specify a task hub for different orchestrator though – adelb Jan 29 '21 at 15:48
  • 1
    I've not used this, but can try defining task hub in `DurableClient` attribute like - `[DurableClient(TaskHub = "%MyTaskHub%")]`. where `%..%` representing to look for value in app settings – user1672994 Jan 29 '21 at 16:46
  • yeah I tried that but it doesn't work – adelb Jan 31 '21 at 21:27

2 Answers2

1

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://learn.microsoft.com/en-us/azure/azure-functions/durable/durable-functions-task-hubs?tabs=csharp

  • That's not what the docs say though. They say: "If multiple function apps share a storage account, each function app must be configured with a separate task hub name." This is not about multiple functions within one Function App, it's about multiple Function Apps sharing the Storage tables/queues if using the same task hub. – juunas Aug 15 '23 at 23:44
0

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.

Daniel Dyson
  • 13,192
  • 6
  • 42
  • 73
  • You can definitely have more than one orchestrator function in one Function App. If you needed them to use separate task hubs because of performance issues, then yes, you could separate them to different Function Apps and use separate Storage accounts for them. – juunas Aug 15 '23 at 23:41