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:
- A server-side process which cascades
Userupdates toPosts - A slightly more pragmatic approach of doing (1) but scoping the update to recent
Posts(e.g. in the last 30 days) - Don't update duplicate fields, meaning updates are only reflected in new posts. This likely wouldn't be acceptable.
- 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.