Stackoverflow shows your status alongside your username. I guess it does not hit the database to calculate your score on every page render (or possibly it will?). Would there be considered a total score area within the customers table that will get up-to-date when someone upvotes me?
What's the best practice of these type of systems? I apologize whether it's an apparent question, I am a new comer to databases.
Whenever you sign in, the amount is drawn in the database together with all of your customers information.
It's really a user object. That user object includes a property score that is initialized to whatever time is incorporated in the database whenever you just sign in.
Along the way round the website and do stuff, the home is up-to-date although not the database.
After that you can update the database only one time once the object user is destructed (either by logout or closing the browser) or after some time.
I believe the overall answer for this type of general real question is: Caching! The thought of caching may be simple, but it is not necessarily easy to get it done right. I'd think that SO not just stores your total score. It stores all "occasions" which supplment your score. Your total score is calculated from these "occasions". To the entire score has already been some type of precalculated or cached value. If you won't want to hit the database for every request, you are able to cache the values in memory. Memcached can be used frequently for such jobs, but you will find other available choices obviously.