Imagine you need implement a system that records your checking account transactions over time. Generally, transactions are grouped by month on your statement. There is a beginning balance, and an end balance for each month. Each transaction between the start and end date increases or decreases the balance. You want to be able to tell your current balance.
What is a good way of representing this data? I came up with these two basic choices:
one big table for all the transactions. To determine the current balance, sum up all transactions. Big downside: the longer the list of transaction grows, the slower it gets. So I suspect that is not what banks would do or anybody who implements this for reals.
same as previous, but with additional "snapshot" information, e.g. a "balance at end of month" table. This way, to determine the current balance, only the transactions of the current month need to be added to the most recent snapshot, which is much faster. The downside is that if a transaction comes in late, or was recorded incorrectly in the past, the snapshots have to be updated. (This should not happen for a bank too often -- I hope --, but might for others if your accounting period -- like for your private life -- is longer than a month)
I was wondering how real-world systems do this.