We have an Azure function with a Cosmos DB trigger that needs to process items within a partition sequentially, but not in any specific order. My understanding is the trigger will always send all changes for a partition to one function instance at a time. However, I am seeing changes for one partition being processed by multiple function instances within a few seconds. So the change feed distribution to function instances is not working as I expect it to.
This function app runs on the latest V2 function host. The function is a durable function. We use a 'leases' collection with a specific prefix to manage the leases for this change feed.
[FunctionName("ProcessChanges")]
public static async Task RunAsync([CosmosDBTrigger(
databaseName: "MyDatabase",
collectionName: "MyCollection",
ConnectionStringSetting = "AzureWebJobsCosmosDBConnectionString",
LeaseCollectionName = "leases",
LeaseCollectionPrefix = "chgproc",
CreateLeaseCollectionIfNotExists = true)]IReadOnlyList<Document> documents,
[OrchestrationClient]DurableOrchestrationClient starter,
ILogger log)
{
// Processing code that calls the orchestrator function
}
I expect all changes for a given partition at a given time to go to one function instance, but sometimes they go to multiple function instances.