yoklainterview sim

Backend Caching Interview Questions

75 verified Backend Caching interview questions — solve with answers, learn from explanations, test yourself in a real simulation.

Try the real simulation →

Sample questions

CachingDifficulty 1
What is the primary purpose of adding a cache in front of a slow data source?
  • aTo encrypt frequently accessed data so it is served more securely
  • bTo keep frequently accessed data in fast storage, reducing latency and load on the source
  • cTo guarantee that cached data is stored durably and survives process restarts and machine crashes
  • dTo reduce the overall memory consumption of the application at runtime
Explanation:A cache trades memory for speed: frequently requested data is served from fast storage instead of being recomputed or re-read, which cuts both response time and load on the backing source. Durability (c) is the opposite of what caches offer — cached data is typically volatile — and caches consume extra memory rather than saving it (d).
CachingDifficulty 1
In caching terminology, what is a cache hit?
  • aThe requested data is found in the cache and served from it
  • bThe requested data is not in the cache, so the source must be queried
  • cThe cache is full and an existing entry must be evicted
  • dA cached entry has become inconsistent with the source data
Explanation:A hit means the lookup succeeded and the request is served from the cache. Option (b) describes a cache miss, (c) describes eviction, and (d) describes staleness — three related but distinct concepts.
CachingDifficulty 1
A cache reports a 95% hit ratio. What does this metric mean?
  • aThe cache is using 95% of its allocated memory
  • b95% of the cached entries are still consistent with the source
  • c95% of lookups were answered from the cache
  • d95% of write operations were routed through the cache
Explanation:Hit ratio is hits divided by total lookups: at 95%, only 5% of reads had to reach the backing store. The metric says nothing about memory usage (a) or about how fresh the entries are (b).
CachingDifficulty 2
What is the fundamental trade-off when choosing a TTL (time-to-live) for cached entries?
  • aA longer TTL raises the hit ratio but widens the stale-data window
  • bA longer TTL makes data fresher but increases memory usage
  • cA shorter TTL improves both freshness and hit ratio at the same time
  • dTTL affects only write throughput, not read behavior
Explanation:Entries that live longer are found in the cache more often (higher hit ratio) but can lag further behind the source (staleness). A shorter TTL buys freshness at the cost of more misses — you cannot maximize both, which is why (c) is wrong.
CachingDifficulty 2
value = cache.get(key)
if value == null:
    value = db.query(key)
    cache.set(key, value, ttl=300)
return value

Which caching pattern does this code implement?
  • aWrite-through: writes update the cache and the database together
  • bRead-through: the cache library itself loads missing values from the database
  • cCache-aside: the application checks the cache and loads/populates it on a miss
  • dWrite-behind: writes are buffered in the cache and flushed to the database later
Explanation:The application code itself handles the miss: it queries the database and fills the cache. That is cache-aside (lazy loading). In read-through (b) the cache component — not the application — performs the load; (a) and (d) describe write paths, while this snippet is a read path.
CachingDifficulty 2
In a write-through caching strategy, what happens when the application writes data?
  • aThe write goes only to the cache; the database is updated asynchronously later
  • bThe write goes only to the database; the cache picks up the new value on the next read
  • cThe write clears the entire cache to avoid any inconsistency
  • dThe write is applied to the cache and propagated to the database as part of the same operation
Explanation:Write-through keeps cache and store consistent by writing to both synchronously. Option (a) describes write-behind (write-back), and (b) is how a cache-aside setup typically behaves on writes.

Test yourself against the 3300-question Backend bank.

Start interview