I'm designing a database for tracking stock transactions & real-time portfolio holdings. The system should be able to pull historical position on a custom time-period basis (e.g. end of day holdings). My current design includes a transaction table and a real-time position table, when each transaction is booked into the database it will automatically trigger the update of the real-time position table. I'm planning to use PostgreSQL and the TimescaleDB extension for the transaction table.
I'm kind of confused about how to implement the function of historical holdings, as the historical holdings as a certain timestamp t
can be derived by aggregating the transactions with timestamp <=t
together. Should I use a separate table to record the historical holdings or simply do the aggregating? I am also considering use binary files to store snapshots of real-time positions at end of each day to support the historical position look-up.
I have little experience with Database design thus any advice/help is appreciated.