Caching computed results: when to cache at the query level vs application level
Pierre Watanabe
·73 views
we have several expensive aggregation queries that power dashboards and leaderboards, taking 5-10 seconds to run directly against our database. we need to cache these results to improve user experience. the question is, at what level do we cache? do we cache the final computed result for a specific dashboard view, or do we cache intermediate, per-user metrics that can then be aggregated on the fly? caching the final result is simpler but less flexible if aggregation parameters change. caching intermediate metrics offers more flexibility but introduces complexity in cache key design and potentially more cache entries to manage. what are the trade-offs you've considered when deciding between caching at the query level (final result) versus the application level (intermediate data) for expensive computed results?
8 comments