'What database structure for a banking app? [closed]

I am currently programming a finance app and I would like to perfect the database.

Briefly to get into the app: I have different accounts and each account can have multiple transactions.

My question now is: How should I structure the database?

1st variant: the accounts do not have their own value, but every time the app is opened, the current account balance is calculated from all transactions.

2nd variant: There are all transactions and the accounts table has an own account balance. If you now create a new transaction, the transaction is automatically added to the account for each transaction.

I have learned that you should do it like in the 1st variant and I would do it also in such a way. But the question I asked myself is that if you eventually have 10,000+ transactions, this variant will have very high read costs and performance problems, won't it?

What would be the pros and cons to each variant and which one would you finally use?

Thank you very much for your answers.

(I use Flutter/Dart with Firebase as database).



Solution 1:[1]

Mot systems store snapshots of the calculated balance (or other aggregated values) at regular intervals to speed looking it up. This also prevents having to read all transactions to calculate the simple balance value. This is just another type of caching, so you'll need some type cache invalidation/update strategy.

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 Frank van Puffelen