Skip to content
Tech Interview Prep
Technical interview guide

Caching Strategies

Production caching for technical interviews: placement, read/write patterns, freshness, stampedes, HTTP caching, observability, failure recovery, and decision tradeoffs.

Minutes to read
3
Practice MCQs
25
Interview Q&A
25
Edition
v5
Editorial status
Reviewed

Scope: HTTP caching per RFC 9111 and RFC 5861; Redis behavior referenced from current official documentation accessed 2026-08-30..

Overview

Curated: · Written: · Reviewed:

Caching Strategies

In one line

A cache keeps a reusable result near the caller so hits skip a slower source. Reach for it when keys repeat, the product can state a staleness budget in seconds or minutes, and the miss path can carry full traffic if the cache goes cold or down.

Key definitions

  • Hit ratio: share of lookups served from cache. Quote request hit rate and byte hit rate separately, because a few large objects can dominate bytes.
  • Cache-aside: the application reads the cache, loads the source on a miss, then writes the cache.
  • Write-behind: the cache acknowledges a write and flushes it later, so until the flush the cache holds the only copy.
  • Stampede: many callers miss the same expired key together and all reach the source.
  • Stale-while-revalidate and stale-if-error: Cache-Control extensions from RFC 5861 that permit serving a stale response during background refresh or origin failure.
  • Fencing token: a monotonic number the store checks so an expired lock holder cannot overwrite a newer write.

Formulas and complexity

E[latency]=h⋅thit+(1−h)⋅tmissE[\text{latency}] = h \cdot t_{hit} + (1-h) \cdot t_{miss} E=0.90×2 ms+0.10×50 ms=6.8 msE = 0.90 \times 2\,\text{ms} + 0.10 \times 50\,\text{ms} = 6.8\,\text{ms} source rps=R⋅(1−h)=10,000×0.10=1,000\text{source rps} = R \cdot (1-h) = 10{,}000 \times 0.10 = 1{,}000

These are hypothetical figures. The 50 ms miss time is the full miss path, including the 2 ms lookup.

How it works

A lookup either returns the value or triggers one fill. Single-flight lets one caller load the source while the others wait on that fill. The fill writes the entry with a jittered TTL and a version, so a late writer can be detected and rejected.

yes no Request Cache hit? Return value Single-flight fill Read source of truth Write cache with TTL and version

When to use and when not to

SituationCache?Why
Repeated reads, staleness budget of seconds to minutesYesHits remove source work
Mostly unique keysNoEntries expire before reuse
Must reflect the latest committed writeOnly with explicit invalidation or versioningTTL alone cannot guarantee it
Authorization or balance decisions during an outageNo, fail closedStale answers are unsafe
Write-heavy with read-after-write needsInvalidate after commit, or write-aroundWrite-through still races
Lost acknowledged writes unacceptableWrite-through or commit to source firstWrite-behind holds writes in the cache

Traps interviewers probe

  1. Believing write-through means never stale. Fix: write-through still faces partial failure, concurrent writers, retries and replication lag. Commit to the source first, then update or invalidate the cache idempotently.
  2. Deleting the key after the database write and assuming no race. Fix: a slow reader can store version 7 after version 8 invalidates the key. Use version checks or compare-and-set on store, and keep a bounded TTL as a backstop.
  3. Deleting only the L2 key. Fix: L1 copies survive. Cap the L1 TTL (for example 30 s) and define what happens when an invalidation message is missed.
  4. Sizing for hit rate. Fix: at 10,000 rps and 90% hits, the source still sees 1,000 rps, and a cold cache sends about 10,000. Load-test the miss path with the cache disabled.
  5. Unbounded fallback during a cache outage. Fix: bound fallback concurrency, use a circuit breaker, shed noncritical traffic, and fail closed on authorization.

Interview tips

Opening: "The cache is justified by reuse and a freshness budget of X. The miss path must survive Y requests per second, so I would size and load-test that first."

Expect these follow-ups: the write race in cache-aside, stampede control on a hot key, key design for tenant and locale, CDN privacy for authenticated responses, and what happens when invalidation messages are lost.

30-second outline:

  1. Goal: which latency, throughput or cost problem the cache solves.
  2. Reuse: which keys repeat and how skewed the working set is.
  3. Freshness: a bounded staleness contract per data class, including during failures.
  4. Pattern and placement: cache-aside or write-through, and which layers.
  5. Correctness: key dimensions, version checks, and invalidation with a TTL backstop.
  6. Protection: single-flight, TTL jitter, hot-key handling and backpressure.
  7. Evidence: hit and byte rate, miss penalty, source load, evictions, and a cache-disabled drill.

Feedback on this overview

Log in free to save your progress and keep bookmarks and notes for a quick revision before your interview.