Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Keeping Track of User Points (Like SO)

Tags:

c#

sql

asp.net

I want to be able to keep track of user points earned on my website. It isn't really like SO but the point system is similar in that I want each user to have a total and then I want to keep track of the transactions that got them to that total.

Should I keep a user total in the User table or should I just pull all the transactions that affect the User in questions point total, sum them and show the point total?

Seems like the latter is more work than needs to be done just to get the total. But then again I cringe at the idea of keeping the same data(more or less) in two different places.

What's the right way to design this?

EDIT: Took the advice. Using both and recalcs. I added a RecalcDate column, and if its over a day old it gets recalced. The total also get recalculated everytime a user does something that should affect their point total.

like image 297
Jason Avatar asked Mar 01 '10 23:03

Jason


People also ask

What do you mean by user tracking?

User tracking or web tracking allows you to track an Internet user anonymously and by various means while browsing your website. Tracking can be implemented for statistical, marketing or commercial purposes. See also: Analytics Suite, Targeting, Advert.

What is the importance of tracking the value of user actions?

Conducting user tests on new products or properties entails having real consumers use the product while being monitored. This enables brands to not only understand how the user engages with a product, but also offers insights into what tasks they're trying to achieve and identify problems or friction points.


2 Answers

Both

You need to have a way of recalculating totals when things go wrong, say you add a new feature, or someone learns to exploit the system. You can keep a current total on the user table and a record of transactions to recalculate that total when needed...not every time you need the value to display.

You're not storing duplicate data so much as the audit history to fall back on, the only duplicate is one number in one column on the User table...the alternative is a user exploits the system, there's no way to roll it back. The same thing happened in the early days of SO, but they had the history and could recalculate totals without a sweat.

like image 172
Nick Craver Avatar answered Oct 21 '22 03:10

Nick Craver


You should probably do a mix of both.

Keep a running total on the User table and also keep a log of each transaction that affects the user total, that way you don't need to do a sum of all the records, but you'll have them just in case.

The numbers may get out of sync, which is why you might need to do a recalc every now and then. (StackOverflow calls it a recalc, where they go through and update your reputation to what you should have).

like image 32
Brandon Avatar answered Oct 21 '22 03:10

Brandon