Let's say you have a site that allows users to post questions and answers like this one. With each Question, you can have associated items like quantity of flags, answers, likes, views., etc.
Will have separate tables for flags, answers, likes, etc. so can hit the database to find the totals for each question, then post the data to display with each question listing. This maintains the integrity of the data throughout, which is good, but requiring several additional database hits/queries.
Or could have these quantities as part of the question record with a field for flags, answers, likes, views, etc. and have that field manipulated each time something is added or deleted. This would be faster as the system would not need to hit the database 4 or 5 extra times to get these quantities.
Then you would run a cronjob every night to correct the values in the questions fields if these two sources are out of sync (individual tables as the correct one).
Is this a good idea or bad idea? Should I worry about hitting the database 4 or 5 extra times for each question that gets listed? Just starting development at this point and would appreciate feedback on when this would be ever be a good idea, or never. If never, then when is it a concern, or do you just add more $$ and bandwidth as your community grows and don't worry about it.
Perhaps there is a better approach?
Thanks in advance!