1
votes

I'm following this msdn guide on creating a Azure Function that's triggered by CosmosDB - https://docs.microsoft.com/en-us/azure/azure-functions/functions-create-cosmos-db-triggered-function

It's still not clear to me what db operations actually trigger the Azure Function though - the example, a new document is created via the CosmosDB Management Portal. So we know that document creation triggers the Az Fx, but what about updates to a document?

Is each update/create operation mapped to a single triggering of the azure function or is it batched?

1

1 Answers

4
votes

The Cosmos DB Trigger is tied to the Cosmos DB Change Feed. Basically, the Feed publishes all inserts / updates that happen in a collection (not deletions, unless you are using soft-deletes, which is actually an update) in an ordered fashion.

The Trigger internally leverages the Cosmos DB Change Feed Processor Library, so your Function will receive batches of inserted / modified documents.

The size of the batch depends on the frequency of the operations. If you are inserting 1 document every second, your function might probably fire with a batch of 1 document several times; if you insert 10 documents every second, the batch will have those 10 documents. It's not a direct relationship with docs/second but just so you get the idea that the Function will always get a batch, and the batch size depends on the volume of operations.

In your Function code, the input in C# is a IReadOnlyList<Document> and in Javascript is an JArray (or simply an array).