Search code examples
azure-cosmosdbazure-cosmosdb-changefeed

What should be the minimum TTL value for Azure Cosmos db, so that it goes to change feed


If I set TTL of a document in azure cosmos db to be 1 sec, then it never reaches changefeed What is the reason for that? Most probably, before the change diff can be computed the data is deleted.

If that's the reason, what should be the minimum value of TTL, which guarantees that it will land up in change feed ?


Solution

  • Setting the TTL to 1 second it's a Replace operation. It will appear on the change feed. The key there is, you need to have something in place (Change Feed Processor, Azure Functions) that would react in less than 1 second (read the change and act on it), otherwise it will miss it.

    So the amount of seconds to set on the TTL is equal to the amount of seconds it takes to your detection mechanism to pick it up.

    Having said that, you can actually turn around the scenario. Why not add a "delete" flag on the document (soft delete), and when it gets picked up by your Change Feed detection mechanism, set the TTL to 0 on it? That would first let you detect the deletion intent and act on it, and then, setting the TTL to 0 would delete the document without a second Change Feed notification.