Readyset Weekly: Issue 50
How to Know Which Queries Are Actually Worth Caching
Adding a cache in front of your database sounds straightforward until you have to decide what goes in it. Cache everything, and you waste memory on queries that rarely repeat. Cache the wrong things, and you end up maintaining freshness logic for data that changes constantly. The question of which queries are worth caching is where most of the real work lives.
Patterns that reliably identify good caching candidates:
- High execution frequency with stable results. Queries that run thousands of times per hour and return the same result are the clearest win. The cache absorbs the repetition and eliminates redundant work. Low-frequency queries are less likely to justify caching, unless they are particularly expensive.
- High execution cost relative to data change frequency. Expensive joins, aggregations across large tables, and complex filters all benefit from caching when the underlying data changes infrequently. A query that takes 400ms and runs every few seconds on data that updates every 30 minutes is almost always worth caching.
- Deterministic queries with no non-deterministic functions. Queries that use functions like
NOW()orRAND()can return different results on every execution, which makes them harder to cache. Parameterized queries with stable, predictable inputs are the ones to focus on. - Tolerance for staleness. User profiles, product catalogs, and aggregate statistics can tolerate brief staleness. Transactional data like account balances or inventory counts typically require stricter consistency guarantees and are less ideal for caching without careful invalidation. If results need to be exact in real time, they're poor candidates for traditional caching. In most systems, this leads to complex invalidation logic. Systems like Readyset handle this automatically by keeping results up to date, without manual invalidation logic.
Identifying these queries manually requires time that most teams don't have. It's often done during incidents or performance investigations, rather than maintained as workloads evolve. As a result, caching decisions may not always reflect current query patterns. Readyset QueryPilot is built to address this. It observes live traffic, identifies high-frequency, high-cost queries, and caches them automatically at the SQL layer, without requiring cache keys, TTL rules, or code changes.
For a deeper look at how to evaluate query patterns and decide what to cache, this post is worth the read.
🔍 What We're Watching in the Database Ecosystem
Database Performance Strategies and Their Hidden Costs
ByteByteGo's latest piece frames something most teams learn the hard way: every database optimization helps one thing and can hurt another. Indexes speed up reads but slow down writes. Caching reduces load but introduces stale data. Denormalization makes queries faster but complicates updates. A useful read for anyone who has ever fixed a slow query and then broken something else in the process.
Best Practices for Database Optimization in High-Performance Environments
A well-structured piece on what database optimization actually involves at scale, not just adding an index or rewriting a query, but understanding workload patterns, reducing contention, and making changes based on evidence rather than guesswork. The core argument: a well-optimized database supports the application instead of becoming the first place performance problems appear. Good foundational reading for any team where the database has started to slow things down.
In Case You Missed It
New on our blog: How Hussle Technology Used Readyset QueryPilot to Absorb Peak-Season MySQL Load, dropping to near-zero active sessions on the primary during their highest-demand windows, across 11 databases and nearly 1,700 cached queries, without touching application code.
Replication Internals: Decoding the MySQL Binary Log, Part 5 - GTID Log Event: The Global Transaction ID: Marcelo continues the series with the GTID Log Event, the mechanism that gives each transaction a unique, globally consistent identity across the replication topology. If you're working with MySQL replication or CDC tooling, this one is foundational.
And if you missed last week: the Introducing Readyset Shallow Cache webinar is still available to watch.
Get Readyset Weekly in your inbox
One email a week — what shipped, what we learned, and what is worth reading.