I am building an app with another developer at the moment, and we are struggling to agree on the design of a particular function :-)
One part of our app allows users to comment and like posts (similar to facebook)
So we have the following tables (in relation to this part of the app) in our Parse.com database:
- users (id, fullname, email, username, etc)
- posts (id, user_id, message, etc)
- replies (id, user_id, message, etc)
- likes (id, user_id, post_id, etc)
However, the other developer feels that in order to load the posts quicker, we should also store the username and number of likes in the posts table too (in addition to the other tables), so that the app loads the data faster, as it wouldn’t have to query all of the tables for the all the data for a post, so it could get the username, no. of likes from the 'posts' table alone.
I firmly believe that you should never store the same data twice in a database, and that you should use an id to link all of the pieces of data together from different tables.
What do you think is the best approach?