How to optimize a system with balance and in-out TXs to avoid re-calculating user's balance?
1
vote
0
answers
27
views
I work on a service wherein a user will have balance, will be able to deposit and withdraw money, perform actions that generate and burn it. As the amount of the transactions grow, the amount of them involved in calculating user's balance will too.
I want to optimaze it. I don't want to cache the value. Rather I want to be able to prune the system and do so properly.
Let's say, for the last 6 months a user made 100 TXs and activities, plus and minus, which in sum have result in $50 on user's balance. Since **it's already in the past**, why would I calculate it every single time **ever again?**
**Questions:**
How will I properly prune, optimaze the system such that the next time I need to calculate a balance, I'll start off with
$10
? Meaning, I'd prune it every 2-3 or 6 months, not every day or week.
How will I change the Db schema of finance_transactions
table? Should I add is_achieved
field and, once I've calculated a new balance as a new starting point, I'd achive all the existing TXs and create a new TX manually with the amount of user's balance?
Asked by nicholas.fowler
(11 rep)
Oct 14, 2023, 05:45 PM
Last activity: Oct 14, 2023, 05:46 PM
Last activity: Oct 14, 2023, 05:46 PM