Given an app that manages appointment bookings, I'm separately storing purchases, bookings made, or cancellations (some of them non-refundable) and am required to show the sum of these, based on different conditions, in the form of one number.
Right now the application will fetch the entire dataset and recalculate this count every time a transaction (purchase of packages, booking made...) is made, but his is too expensive in terms of resources (and money as well). So I'd like to mitigate this by storing the count in its own field, and while keeping the mechanism of storing the transactions individually for history purposes, the ideal scenario would be if I could just keep updating this one field and simply getting the value of it instead of having to constantly recalculate.
The question is: how often would it be practical to still do a recalculation (self-check or audit) to ensure the count is still correct? How can I decide what best audit points should be?
Someone I asked told me to do the recalculation, say, every 3rd time the user logs in. I was thinking I could do the recalculation only if there was an error during any of the transactions, but that might not be sufficient.
Or is this a question that could really only be answered very vaguely or subjectively...?