Skip to content
Devgo

Read-through

A caching pattern where the cache itself loads missing data from the DB on a miss, transparent to the app. The app only talks to the cache. Cleaner than cache-aside but needs a cache provider that supports it.

When to use
  • When your cache provider supports read-through loaders.
  • Apps wanting a single, consistent read path.
When not to
  • When you need explicit control over cache population.
  • Caches without loader support.

Definition

The app calls cache.get(key); on a miss the cache synchronously fetches from the DB (via a configured loader), stores, and returns. The app code is unaware of the DB on the read path.

Why it exists

Centralizing the load-on-miss logic in the cache provider keeps app code simple and consistent, and can coordinate concurrent misses (single-flight) to avoid stampedes.

How it works

Configure a read-through loader. On miss, one request loads from DB while others wait (or all load — depends on provider). The cache populates and serves subsequent hits. TTLs bound staleness.

Scaling limits

Miss latency includes DB load. Without single-flight, concurrent misses still stampede. The cache provider must support the loader abstraction.

Cost shape

Same as plus provider features. Blow-ups: stampedes without coalescing and large objects filling the cache.

Alternatives

  • Cache-aside — Explicit control, but app manages the miss path.
  • Write-through — Keeps cache fresh on writes too.

Failure modes

  • Stampede if no miss coalescing.
  • Loader failures surfacing as cache errors.

, , ,