asp.net - Best practice for storing credit balance in web application -


i creating web application users can buy credits (using real money) , spend them on things.

i need keep history of every time user buys or spends credits.

i need know user's current credit balance.

i work principle storing same data twice bad practice i.e. since have history of increases , decreases in credit balance, should not store balance seperate field.

however, seems overkill calculate balance each time user opens new page (which display current balance). on other hand, seems wrong store either in database, or in memory on webserver, prevent system having work out each time.

does have experience of , / or know recommended best practices situation?

i've worked on several projects similar requirements, , there's nothing wrong calculating current balance on fly - it's least error prone solution, , kind of query databases designed do; unless you're working on site facebook-levels of traffic, "select sum(transactionvalue) transactions userid = ?" should blazingly fast.

storing balance somewhere else - duplicating it, in effect - risks introducing subtle bugs , discrepancies, "cache" value getting out of sync underlying transactions; amount of work required right significant.


Comments