Caching medium
A high-traffic service uses a 'Two-Layer Cache': L1 (In-Memory Guava) and L2 (Redis). What is the primary trade-off of introducing L1?
- A L1 increases network bandwidth usage.
- B L1 introduces 'Cache Incoherence' risk; different app instances might hold different versions of the same data in their local L1.
- C L1 is slower than L2 due to garbage collection.
- D L1 cannot store objects, requiring expensive serialization.
Answer: B. L1 introduces 'Cache Incoherence' risk; different app instances might hold different versions of the same data in their local L1.
Introducing an L1 (local in-memory) cache creates a distributed system problem: **Cache Coherence**. If Instance A updates a record and invalidates its L1/L2, Instance B might still hold the old value in its L1 cache. This stale data persists until Instance B's L1 entry expires, leading to inconsistent behavior across the cluster.
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?