Open
Description
Currently a user balance in a currency is an entry in a table that we update (e.g. "Bob has 34 gold"). We should change this to be a append-only log of transactions (e.g. "Bob gained 10 gold", "Smith spent 10 gold"), this will bring the following benefits
- Allow to link specific transactions with events/actions in other parts (e.g. buying an item)
- Rolling back transactions, in the event we have an incident and need to undo a transaction is as simply as removing or doing the opposite operation. Otherwise we would need somehow figure the previous balance which sounds very hard
As an additional part of this work, but that can be done in a subsequent task there are 2 more tasks:
- We should also a sort of cache to avoid calculating the balance of each user every time as the more users we have and the longer they are playing will make this calculation expensive
- Compaction strategy, we could decide to compact transactions from after X amount of time (e.g 1 year) into a single entry and that way keep transactions on a manageable size. During this compaction we could move the compacted transactions to a separate table/cold storage to not fully loose them and have them at hand in case of emergencies