0

We are currently looking to migrate from Sql to CosmosDb(DocumentDb). To use the advantages of CosmosDb, we had to denormalize the data. However, there are cases where we still need to update the related tables if data in the original table changes. To achieve this, we are planning to use Change Feed to propagate any changes to the related table.

For ex: Consider a scenario with two collections

1) User Collection

keys/columns per document : id, name, displayName

2) Post Collection

keys/columns per document: id, userDisplayName, userid

Lets assume that one of the documents in user collection has its displayName changed. We need to update all the documents from post collection with that displayName to keep Post collection up to date (Cost to be paid for denormalizing)

We can process all the documents from post collection matching the displayName of the changed user document. If there are other keys in user document that changes frequently, processing all the posts for that user is expensive and unnecessary if that column is not even a part of the Post document.

I couldn't find any information on Change Feed providing information on what columns changed. If not, do I have to bear this cost or is there a better way to design ?

Cool Geek
  • 79
  • 2
  • 7
  • @MatiasQuaranta Yeah, I think it answers for the most part. But, as I mentioned, I want to update the documents in a related collection. Is there any other recommended solution to this other than updating all those documents(in related container) for every change ? Is there a better pattern ? – Cool Geek Feb 19 '20 at 19:18
  • 1
    Well, your Post collection only has the user id (which cannot change) and the display name. The only way I see is updating all related documents. You could in theory do it in a async way. Read 1 Post of the user and check if the displayName changed vs what came in the Change Feed. If it did, save an item in a queue that will update all Posts for the user with the new value and not block the Change Feed listener (if you worry you might get too many events). – Matias Quaranta Feb 19 '20 at 20:12
  • Thanks for the response. I had something similar in my mind to only update the related documents whose data is different after comparing. – Cool Geek Feb 19 '20 at 21:32

0 Answers0