So for example, if you had a users table, and a friends mapper between users. Should you add an extra column in users called ‘friends-count’ and update it every time they add a friend, or should you just do a count query every time you need the count. Which one is more efficient?
Share
Why would you have two versions of the truth and what would you do if they got out of sync… And how would you determine that.
The most efficient eay is to count each time, the support and validation effort the maintain a cache are likely to outweigh any computational benefit. CPU cycles are cheap compared to effort from devs.
If it ends up being a bottleneck in your app then look at caching, you then have a tangible benefit for the caching.