How are account balances persisted

by Daniel Benzie   Last Updated October 11, 2018 14:05 PM - source

I am currently building a finance application that contains "accounts"

Each account has a balance that is dynamically generated based on platform charges vs payments. e.g simplified example.

$account->balance = $account->transactions->sum('amount') + ($account->charges->sum('amount')) 

It's obviously very simple however as the data is not persisted it is impossible for to run queries, sort by balance on.

Is it best practice to store a static balance for accounts ? I can obviously update the balance using events whenever a new charge or transaction is reconciled against the account. I would be interested to know solutions to this problem.

The application is Laravel but I don't believe that is important in this scenario.

Related Questions

Delete user data when they sign out?

Updated December 30, 2016 08:02 AM

How to notify a repository about persistence changes

Updated September 15, 2017 10:05 AM