Azure Function: Understanding Cosmos DB trigger lease file

Ramkumar Balasubramaniam
CodeX
Published in
1 min readOct 13, 2023

In my previous post we see where Azure function EventHub trigger stores the checkpoint information and how we could reset the checkpoint. In this post we’ll see another type of Azure function binding and understand the content of it’s checkpoint/lease file.

As name suggests, Cosmos DB trigger function is another type of trigger which get fired whenever a new document is created or any of the existing document is updated within any of the configured collection. Please note that at this time of writing, cosmos DB trigger does not trigger when deleting a document .

So, now let see the example content of the Cosmos DB checkpoint/lease collection document. Below is the sample checkpoint/lease document:

There are 2 documents created in the lease(default name) collection when a specific collection is referenced in the Cosmos DB trigger function.

  1. Info file— basically this holds info about collection:
{
"id": "<account_name>.documents.azure.com_Cosmos database _rid value>_<Cosmos collection _rid value>.info",
"_rid": "Or0zAKFb9w8GAAAAAAAAAA==",
"_self": "dbs/xcdd==/colls/dfg134=/docs/bbbdfer1temp==/",
"_etag": "\"4300f2ea-0000-1000-0000-63d9a5220000\"",
"_attachments": "attachments/",
"_ts": 1675207970
}

2. Checkpoint/Lease file per partition — this holds checkpoint info for a specific partition

{
"id": "<account_name>.documents.azure.com_<Cosmos database _rid value>_<Cosmos collection _rid value>..<partitionId>",
"_etag": "\"2800a558-0000-0000-0000-5b1fb9180000\"",
"state": 1,
"PartitionId": "0",
"Owner": null,
"ContinuationToken": "\"19\"",
"SequenceNumber": 1,
"_rid": "BeRbAKMEwAADAAAAAAAAAA==",
"_self": "dbs/xcdd==/colls/dfg134=/docs/bbbdfer1temp==/",
"_attachments": "attachments/",
"_ts": 1528805656
}

I’ll try cover the details of an each of the properties in a separate blog.

--

--