How are account balances persisted

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

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

Updated June 16, 2018 12:05 PM

Updated May 01, 2016 09:02 AM

Updated December 30, 2016 08:02 AM

Updated September 15, 2017 10:05 AM

Updated May 27, 2018 09:05 AM