| Assume I am creating a webapp which can receive money from the users to their "accounts" in my system and send them out, something like a super simplified version of a bank. Are there any guides, practices to make it safe and properly? I see multiple ways of doing the same thing. For example, when a user puts in $10, then $3 then $7, then moves out $4, I can use a table in the database called balances and add or subtract a single number in the column - 0 + 10 + 3 + 7 - 4 = 16. So, I keep in the column value of 16. Another way is to add rows into a table called "transactions" and calculate the current balance every time I need it. In this case, if there are thousands of transaction for the user, I would need to calculate thousands of numbers every time I need to know balance. I don't want to reinvent the wheel so I would be happy to just have some guide of how these things are usually implemented even though I understand there is no such scenario as "standard" one and there are always myriads of small differences between different implementations. In what direction should I look to understand how to build such a system in a better way and avoid mistakes? Thanks! |
You can have a job to go through the transactions from time to time to save important balances that user would need (e.g: daily, monthly and quarterly balances).