Caching easy
System A has a Cache Hit Ratio of 99%. System B has a Hit Ratio of 50%. Assuming cache reads take 1ms and DB reads take 100ms, which statement is true?
- A System A experiences significantly lower average request latency than System B due to the high hit rate.
- B System B is inherently more efficient because it forces more frequent data refreshes from the main database.
- C The performance difference is negligible because both systems utilize a similar total amount of cache memory.
- D System A is likely suffering from 'Cache Pollution', as it is holding onto too much data for too long.
Answer: A. System A experiences significantly lower average request latency than System B due to the high hit rate.
Average latency is calculated as `(HitRate * CacheLatency) + (MissRate * DBLatency)`. With a 99% hit rate, System A pays the expensive 100ms penalty only 1% of the time, resulting in an average latency of `~2ms`. System B pays it 50% of the time, averaging `~50.5ms`. The difference is an order of magnitude, not just a minor gain.
One system design question a day, with spaced repetition so the ones you miss come back.
Get the appRelated questions
- In the Cache-Aside pattern, what happens when the application requests data that is missing from the cache (a 'Cache Miss')?
- Why use a centralized Distributed Cache (like a Redis Cluster) over local in-memory caches on each web server?
- Setting a short TTL (e.g., 60 seconds) on a cached object helps to:
- What is the primary architectural goal of introducing a cache into a system?
- Most caching systems rely on the principle of 'Temporal Locality', which states:
- Your cache uses an LRU (Least Recently Used) eviction policy. When the cache is full, which item is removed?