How can caching query results help performance, and what are the risks of stale cached data?
Last updated
Caching stores expensive query results (in app memory,
Redis,Memcached, or DB caches) to cut latency and database load.The risk is staleness: after a write, the cache serves old data until invalidated, so users may act on wrong prices or balances.
Mitigate with TTL expiry (simple but leaves a stale window) or invalidation on write (fresher but harder). Avoid caching strongly consistent values.
- https://reintech.io/blog/enhancing-application-performance-aws-rds-caching
- https://docs.aws.amazon.com/AmazonElastiCache/latest/dg/caching-database-query-results.html
- https://www.prisma.io/blog/benefits-and-challenges-of-caching-database-query-results-x2s9ei21e8kq
- https://docs.snowflake.com/en/user-guide/querying-persisted-results
- https://learn.microsoft.com/en-us/azure/synapse-analytics/sql-data-warehouse/performance-tuning-result-set-caching
- https://www.prisma.io/dataguide/managing-databases/introduction-database-caching