Mutual credit accounting is very easy because you just store all the transactions in one table with
- a payer
- a payee
- a quantity
, and then add up all the transactions per user to get the balances. However once a mutual credit system gets larger, it becomes expensive to add up all these transactions. So a caching strategy is needed.
The easiest and most obvious caching is on the member balances. But there are two other main needs:
- the transaction histories per user look better with a running balance figure, as we are accustomed to on our bank statements. So every time you want to see a running balance (as opposed to the present balance), you need to refer to, or recalculate the whole transaction history per user.
- There is one more consideration that, at some point you may want to just cache all transactions before, say, 2008 to save adding them all up ever again.
In order to calculate the highest spenders, or the most frequent earners, or the average transaction size, the whole transaction history needs to be parsed, or updated after every transaction. This is also expensive.
There is a trade off between the quantity of cached objects to manage, and the processing power needed to do all the recalculating. I'm not looking for ultimate efficiency, but to set the software off in the right direction. So which of these seems like the right direction to you?
- Have 2 kinds of caches. A transaction cache which stores all the entries in the users' statements, which is one entry per user per transaction, showing the running balance. And a system wide cache. The latter need not be completely refreshed, but can be incremented and checked occasionally.
- To cache everything before 2008, and calculate everything dynamically from there. This would mean moving all the old transactions into an 'archive' table and creating a table with all the stats you can derive from payer, payee and quantity.
- If applying a combination of the above, which should be primary?
Part of my unknowing is about the processing power involved and the likely limits of a general purpose machine running a large network. While users might be doing, say, 2 transactions a day, some system accounts might be trading with all users frequently. How many thousand transaction objects can be safely held in memory while they are added up? Perhaps MySQL can add them up more efficiently than any caching mechanism, without loading the whole table into memory?
Perhaps I have a year or two before this even needs thinking about?
Comments3
Hi Matthew - The basic
Hi Matthew -
The basic business problem here is similar to the one that led to database optimizations for OLTP and data warehousing. If you are seeing performance issues brought on by keeping too much legacy data in a table when the vast majority of queries are against recent rows, you can choose a point at which rows are moved from the online, or "live" table and into the data warehouse. The point of inflection can be static, driven by a time cutoff or number of transactions, or it could be dynamic and related to the activity such as query frequency or number of trading partners. The database could also then have a table to hold point-in-time totals/averages which can be fetched instead of doing expensive queries against the DW tables.
A well-designed online database with good indexing should allow decent performance up to millions of rows in the trivial case of your example of a table with only three columns...although I would add presume the existence of a UID and timestamp value at minimum, and the quantity will most likely involve a join with the table of currencies under consideration and possibly a conversion value. It's probably not something you need to worry about today, but it's good planning. The interesting thing to do would be load testing of different table designs with sample datasets.
cheers,
ps
1) Check this
1) Check this out....
https://dev.mysql.com/tech-resources/articles/performance-partitioning…
2) You need to distinguish in your mind between data that is still subject to change, and data that will/must never change again.
3) Consider spewing all of the latter out to HTML pages with URLs like
cc.matslats.net/archive/mmb3758552/2009/01/index.html
cc.matslats.net/archive/mmb3758552/2009/02/index.html
As static HTML pages the network itself will handle some caching for you in proxy servers en route.
... also ... Have you
... also ...
Have you considered monthly closing of accounts? A one-line-per-member monthly report would provide you with much more manageable quantities of data.