Quick revision
The short answer
Database load is the miss ratio times the request rate: at a 95 percent hit ratio, 20,000 reads per second send 1,000 queries per second to PostgreSQL, and at 90 percent they send 2,000, above its comfortable 1,500. Average latency is about the hit ratio times 1 ms plus the miss ratio times 16 ms, so 1.75 ms at 95 percent and 1.15 ms at 99 percent, while tail latency is set by the misses. The service needs at least 92.5 percent just to sit at the database limit, and a good deal more to survive a cold cache, a peak or a failover, so the hit ratio must be measured per cache with real traffic.
What to remember
In this answer, we calculated that database load equals the request rate times the miss ratio and that average latency is the cache time plus the miss ratio times the database time. At 20,000 reads per second, 95 percent hits give 1,000 queries per second and 1.75 ms, 99 percent give 200 and 1.15 ms, and 90 percent overloads the database. The break-even is 92.5 percent, but cold caches, peaks and failovers demand much more, and since the hit ratio depends on popularity, size, TTLs and how the cache is shared, it must be measured, not assumed.
Your turn
Answer it aloud as you would in the interview, or type your answer below. Then show one part at a time and compare.
Database load is the miss ratio times the request rate: at a 95 percent hit ratio, 20,000 reads per second send 1,000 queries per second to PostgreSQL, and at 90 percent they send 2,000, above its comfortable 1,500. Average latency is about the hit ratio times 1 ms plus the miss ratio times 16 ms, so 1.75 ms at 95 percent and 1.15 ms at 99 percent, while tail latency is set by the misses. The service needs at least 92.5 percent just to sit at the database limit, and a good deal more to survive a cold cache, a peak or a failover, so the hit ratio must be measured per cache with real traffic.
Why this question is asked
Caches are often discussed in terms of speed, but in most systems their real job is protecting the database. A team that says the cache hits 90 percent of the time may think it is doing well, while the database underneath is overloaded. Interviewers ask this question to see whether we can do the simple arithmetic that connects hit ratio, database load and latency, and draw the right conclusions from it. In this answer, we will define the terms, calculate database load and latency, see why a few percent make a large difference, find the minimum safe hit ratio and the headroom we need, and look at what really determines the hit ratio.
1A Quick Recap of the Terms
The hit ratio is the fraction of reads the cache answers by itself. The miss ratio is the rest, one minus the hit ratio. In a cache-aside setup, a miss means the service first asks Redis, finds nothing, then queries PostgreSQL and usually writes the result back to Redis. So a miss costs the cache round trip plus the database query.
In this service, Redis answers in about 1 ms, PostgreSQL in about 15 ms, and the database is comfortable up to about 1,500 queries per second. The service receives 20,000 reads per second.
2Calculating Database Load
Every miss becomes one database query, so the database load is simply the request rate times the miss ratio.
Notice how sensitive this is. Going from 95 to 99 percent hits looks like a small improvement of four points, but the miss ratio drops from 5 percent to 1 percent, so the database load falls five times, from 1,000 to 200 queries per second. The other direction matters even more: dropping from 95 to 90 percent doubles the database load. This is why hit ratio must be monitored per cache, not assumed.
3Calculating Average and Tail Latency
A hit costs 1 ms. A miss costs the 1 ms cache lookup plus 15 ms in the database, 16 ms in total. The average latency is the weighted mix of the two.
| Hit ratio | DB queries/s | Average latency | Status |
|---|---|---|---|
| 90% | 2,000 | 2.50 ms | over the 1,500 limit |
| 92.5% | 1,500 | 2.13 ms | at the limit, no headroom |
| 95% | 1,000 | 1.75 ms | safe in steady state |
| 99% | 200 | 1.15 ms | safe with headroom |
The average looks good in every case, but it hides the tail. At a 95 percent hit ratio, 5 percent of requests take about 16 ms, so the p99 latency is a miss, around 16 ms or more, not 1.75 ms. And when the database approaches its limit, its 15 ms becomes 50 or 100 ms as queries queue, so the tail grows much faster than the average suggests.
4The Minimum Safe Hit Ratio, and Why It Is Not Enough
To keep the database at or below 1,500 queries per second, the miss ratio must be at most 1,500 / 20,000 = 7.5 percent, so the hit ratio must be at least 92.5 percent. That is the break-even point, and running there leaves no margin at all.
The service needs headroom for the moments when the hit ratio collapses. After a deployment that changes the key format or a Redis failover with an empty replica, the cache is cold, and almost every request misses for a while. At a traffic peak of twice the normal rate, even 95 percent hits produce 2,000 queries per second. So a steady-state hit ratio of 98 or 99 percent, plus protections for cold starts, such as warming the cache, coalescing concurrent misses for the same key and limiting database concurrency, is what makes the service safe in practice.
5What Determines the Hit Ratio
The hit ratio is not a setting; it comes from the workload and the cache design. Key popularity matters most: profile reads usually follow a skewed distribution, so a cache holding the most popular 10 percent of profiles may serve 90 percent of reads. Cache size decides how much of that popular set fits. TTLs decide how often entries are thrown away and reloaded. Shared versus local caches matter too: if each of 20 instances has its own in-memory cache, each sees only a twentieth of the traffic per key and misses more than one shared Redis would.
So we measure it with real traffic: hits and misses per cache, exported as metrics, and watched during deployments and peaks. A model like the one above then tells us what any change in the measured ratio means for the database.
6Follow-up questions
How would the numbers change if the cache itself slowed to 5 ms?
The database load would stay the same at the same hit ratio, since it depends only on misses. Average latency would rise to 5 plus the miss ratio times 15: 5.75 ms at 95 percent and 5.15 ms at 99 percent. Two side effects matter more. By Little's law, the number of requests in flight grows with latency, from about 35 to about 115 at 20,000 per second, so thread and connection pools may run out. And if the client's Redis timeout is close to 5 ms, some lookups time out and fall back to the database, which lowers the effective hit ratio and can push the database over its limit.
Why not cache everything forever to get 100 percent?
Data changes, so long TTLs serve stale profiles unless every write invalidates the cache reliably, and memory is finite, so the least used entries are evicted anyway. The goal is a hit ratio high enough for safety with an acceptable staleness, not 100 percent.
Does write traffic affect the hit ratio?
Yes. Every update that deletes or overwrites a cache entry causes the next read of that key to miss. For read-heavy data like profiles the effect is small, but for frequently changing data it can dominate the miss rate.
7Conclusion
In this answer, we calculated that database load equals the request rate times the miss ratio and that average latency is the cache time plus the miss ratio times the database time. At 20,000 reads per second, 95 percent hits give 1,000 queries per second and 1.75 ms, 99 percent give 200 and 1.15 ms, and 90 percent overloads the database. The break-even is 92.5 percent, but cold caches, peaks and failovers demand much more, and since the hit ratio depends on popularity, size, TTLs and how the cache is shared, it must be measured, not assumed.
Open with
The database only sees misses, so its load is the request rate times the miss ratio. At 20,000 reads per second, a 95 percent hit ratio means 1,000 queries per second, which is fine, but 90 percent means 2,000, which is above the 1,500 the database handles.
Then, if they want more
Latency is the cache time plus the miss ratio times the database time: a miss costs 1 millisecond for the cache lookup plus 15 in PostgreSQL, so the average is about 1.75 milliseconds at 95 percent and 1.15 at 99 percent.
The average hides the tail, though: at 95 percent, one request in twenty is a miss, so p99 is about 16 milliseconds, more if the database is busy. What stands out is the sensitivity. Going from 95 to 99 percent cuts database load five times, from 1,000 to 200 queries per second, and dropping to 90 percent doubles it.
The break-even is 92.5 percent, since 7.5 percent of 20,000 is 1,500, but running there leaves no headroom for a cold cache after a deploy, a peak or a failover.
So I would target 98 to 99 percent in steady state, add protections like miss coalescing and database limits, and measure the hit ratio per cache with real traffic, because it depends on key popularity, cache size, TTLs and how many instances share the cache.
About this answer
- Last updated
- 13 November 2026
- Checked
- Its structure and format are checked automatically. Use it as a carefully prepared study note: where a detail matters, confirm it against the official documentation for the version you use. What the checks cover
- Where the question comes from
- Written by Scrivio for practice. It is not taken from an interview.
Report an issue with this answer
Copy the line below and send it to the author with what you found. It carries the address of this page.
Issue with "How does the cache hit ratio determine database load and average latency here, and what...": https://scrivio-interview-library.netlify.app/architecture/caching-strategies/1413b48aa0/