Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

should the user's Account balance be stored in the database or calculated dynamically?

Should the user's Account balance be stored in the database or calculated dynamically?

For accurate results calculating it dynamically make sense but then it might be a problem, when there are many user's and the database grows very large?

Transaction

  • Id (PK)
  • AccountId
  • Type
  • DateTime
  • Amount
  • etc..etc...

AccountBalance

  • TransactionId (PK/FK)
  • BalanceAmount
like image 754
001 Avatar asked Jun 14 '11 09:06

001


1 Answers

In order to keep accurate auditing you should make record of every transaction that affects the users account balance. This means you can calculate the balance dynamically, however for performance reasons I would have the balance stored as well. To ensure the balance is correct though, I would have a daily job run that recalculates the balance from scratch.

like image 111
Clayton Avatar answered Oct 16 '22 15:10

Clayton