10-08-2014, 05:00 AM
Still bad. An even better solution would be to store each transaction as two records - for the src account and for the dst account. This way we could later on compress the old transactions - replace the oldest N hundred transactions for an account with a single transaction, "balance transfer" and thus the number of transactions that comprise a single account's balance would be kept in reasonable numbers. It would even make counting the balance easier, as it would be a single query, as opposed to the previous system that needs two queries (sum(amount) for incoming minus sum(amount) for outgoing). Each money transfer would effectively become two transaction records - one for the src account, the other for the dst account; the amount in one being negative of the amount in the other.
Why do I feel so dumb for not coming up with this natural system earlier?
Why do I feel so dumb for not coming up with this natural system earlier?