Menu
Back to Discussions

Caching computed results: when to cache at the query level vs application level

Chiara Takahashi
Chiara Takahashi
·421 views
We're developing a new dashboard and leaderboard feature, and some of the aggregation queries are pretty expensive, taking 5-10 seconds to run. We definitely need to cache these results. The debate now is whether to cache at the query level (the final aggregated result) or cache intermediate per-user metrics and then re-aggregate them on demand or asynchronously. Caching the final result is simpler conceptually: store the JSON output of the query in Redis and serve it directly. But this means if underlying data changes, we need to invalidate and re-run the entire expensive query. Caching intermediate per-user metrics means more granular control and potentially easier invalidation, but it requires re-aggregation on read, which might still be slow or complex if not designed carefully. There's also the trade-off between freshness and computational cost. What granularity of caching do you typically aim for when dealing with expensive computed results like these?
2 comments

Comments

Sign in to join the conversation.

Loading comments...