Strategy for managing duplicated field updates in a NoSQL database

61 views Asked by At

Given a simple example of a social media application where you have Users and Posts, stored as distinct collections within a NoSQL database (e.g. MongoDB):

Ideally, you'd duplicate fields such as the user profile image URL within Posts for the sake of simplifying data access (i.e. querying for posts on the news feed).

However, if the user updates their profile image you'd want to reflect this within their posts. Is there a commonly used approach to tackle scenarios of this nature?

A few I've considered are:

  1. A server-side process which cascades User updates to Posts
  2. A slightly more pragmatic approach of doing (1) but scoping the update to recent Posts (e.g. in the last 30 days)
  3. Don't update duplicate fields, meaning updates are only reflected in new posts. This likely wouldn't be acceptable.
  4. Don't duplicate fields and perform a lookup (/"SQL join") of complimentary fields.

Appreciate that any solution would be a trade-off of consistency vs resources, but I'm keen to find out what real world solutions are employed.

0

There are 0 answers