Cosmosdb change feed and deleted items
Until Microsoft implements change feed notifications for deletions we have to soft delete items in Cosmosdb if we use change feed notifications.
TL;DR
Cosmosdb has a handy feature where it journals changes which can then be read in another process. My use was for updating an Azure search index (Elastic search variant) whenever I made a change.
But… how do we handle deletions?
Hidden in the documentation is the information that ,,albeit all changes (within a shard) is guaranteed to be in chronological order it is always the last (present) item handed to the change feed process. So when an item is deleted there is no item and, due to implementation, also no event.
Remedy 1: Soft delete the item by marking it as “deleted”. This is a common approach in many a system.
A drawback is that the repository will end up with stale data.
Remedy 2: Soft delete the item as above. Then make sure this information has been conveyed (in my case the item should be deleted from the search database) before properly deleting it.
This is a more complex solution where the logic still has to handle soft deleted items while also adding the complexity of yet a process to scan(?) the repo for items to delete.
Your turn
I have found no uservoice, github or azurefeedback item for voting on getting a delete event; the closest is an item for getting a event for it in Azurefunctions.
In lack of better place I voted there; so can you if you have the need.
Update
I wrote a suggestion of my own here at azurefeedback.
I did try to find an existing suggestion but failed. Am I the only one deleting data? Or the guys at Microsoft will find an already existing suggestion where I can move my votes.
Update
The functionality is on its way
“Support for deletes on Change feed is planned. Do not have an exact ETA but we are targeting some time in 2020.“
Tags: cosmosdb
Another option is to add a ttl on the table and handle the present of the ttl value to manage deletes