Tuesday 23 June 2020

[Suggestion needed] System design: Post / Comment datamodel

Hi all, I want some suggestions regarding datamodel of a project I'm working on. For simplicity, let's assume that we're building a social media platform. There is an user microservice, and a post microservice. Now in post or comment model, we'll obviously store the userId of the author. The question is, should we store the author name and profile picture url in the post or comment table itself? Advantage is, to load a post or to load 20 comments at a time, we can simply get all the data from the same microservice, and a single query to the same table (post or comment). Disadvantage is, whenever user changes name or profile picture, we'll have to update all the posts and comments the user has done in his lifetime, which is a really heavy operation. The second approach will be, as you might have guessed, to not store user details (name, profile picture) in the post or comment, and fetching them from user microservice whenever we get a request for the post. Advantage is we can gracefully handle user name or profile picture changes. Disadvantage is, we have to do at least an additional request to user microservice whenever client asks for a post, or wants to load 20 comments.Any suggestion which approach you'll recommend? If you have any other suggestion, please do share that as well.Thanks in advance!

Submitted June 23, 2020 at 06:40PM by arpanbag001

No comments:

Post a Comment