What it is
In a read-through cache, the application asks only the cache for data. If the cache has the value, it returns it. If not, the cache itself loads it from the underlying store (calls a loader function or queries a configured data source), keeps it, and returns it. The application never queries the database for that data.
Compare cache aside, where the application checks the cache, queries the database on a miss and writes the result into the cache. The read traffic is the same; what moves is the loading responsibility.
Why it exists
With one service, cache aside is simple. With many services reading the same data, each carries its own copy of the loading code, and copies drift: different key formats (so entries are never shared), different TTLs, different error handling, and every reader needs database credentials and knowledge of the schema. Read-through moves that logic into one place, the cache layer, and makes the database an implementation detail behind it.
How it works
- The application calls
get(key)on the cache. - Hit: the cache returns the value from memory.
- Miss: the cache calls its loader (for example
SELECT … WHERE id = ?), stores the result with its TTL and returns it.
Where it lives:
- In-process libraries with a loader function, for example a "loading cache" whose
gettakes the key and computes missing values. These are local to each instance. - Cache products and managed services configured with a data source or read-through provider. Some managed caches sit in front of a specific database and serve reads through themselves (for example DynamoDB Accelerator in front of DynamoDB). A generic Redis or Memcached server does not load from your database on its own; read-through there means a client library or a service wrapping it.
Same hits, different caller. For the same cache size, keys and TTL, read-through misses exactly when cache aside would. The simulation shows the same hit ratio and number of database queries in both set-ups; only the source of the queries changes.
Coalescing. Because all loads go through one component, it can keep one load in flight per key: concurrent misses for a key wait for the running load instead of each querying the database (often called single-flight). Several loading-cache libraries do this per key out of the box. It helps exactly when misses for the same key overlap, which is the hot-key expiry case; it does nothing for rarely read keys. In the lesson's flash-sale scenario it removes about a quarter of the queries.
When to use it
- Many services or code paths read the same data and should share one loading policy.
- You want readers to have no direct dependency on (or credentials for) the database.
- Hot keys expire under load and you want coalescing in one place.
- Your platform offers a read-through cache for your data store.
When not to
- A single service with simple needs: cache aside is less infrastructure.
- Data whose loading differs per caller (different projections, permissions), which a generic loader cannot express well.
- When reads must keep working through a cache outage and you cannot afford a highly available cache tier.
Trade-offs
| Choice | You gain | You pay |
|---|---|---|
| Read-through instead of cache aside | One loading policy, no DB access in readers, easy coalescing | Cache is a critical dependency; loader must know every data shape |
| Coalescing | Fewer duplicate loads on hot keys | Waiters share the leader's latency and its failure |
| Application fallback to the database | Reads survive cache outages | Reintroduces DB access in readers; can overload the DB |
Alternatives
- Cache aside: the application loads; the cache is optional in the read path.
- Write-through (often combined with read-through): writes also go through the cache, keeping it current.
- Refresh-ahead: the cache reloads popular keys before they expire, hiding reload latency.
- Read replicas or materialised views: scale reads at the database layer.
Failure modes
- Cache outage: readers without a database path fail completely. Run the cache replicated; if you add a fallback, rate-limit it.
- Loader errors: a failing loader turns every miss into an error; consider serving stale values while the source is down.
- Hot-key stampede without coalescing: concurrent misses each run the same query.
- Stale data: read-through does not invalidate anything; pair it with write-through, invalidation or TTLs.
- Slow loads hold cache capacity: every in-flight miss occupies the cache tier while it waits for the database.
In production
Treat the read-through tier like a database in availability planning: replicas, health checks, capacity for in-flight loads. Enable per-key coalescing for hot data. Set TTLs with jitter, and decide what happens when the loader fails (error, stale value, default). Monitor hit ratio, load latency, load errors and in-flight loads.
Common misconceptions
- "Read-through has a better hit ratio than cache aside." Same size, keys and TTL give the same hits.
- "Read-through keeps data fresh." It only changes who loads; freshness needs a write strategy.
- "Redis is a read-through cache." Only with a library or service that loads on miss.
- "The database is protected from every outage." If the cache is down, reads fail or fall back to it.
Interview angle
Explain the read path in one sentence, then the trade: centralised loading and coalescing versus the cache becoming critical infrastructure. Mention that it is commonly paired with write-through, and that hit ratio and database load do not change from cache aside. A strong answer adds how the tier is made highly available and what readers do when it is not.
Model assumptions
The simulation is a simplified model, not a benchmark. Users read 10,000 products, Zipf(1) popularity (Zipf 1.5 in the flash-sale steps), Poisson arrivals. The database has 8 connections and a 40 ms mean read (lognormal, cv 0.4). The cache memory is an LRU of 1,000 keys answering in about 1 ms. In the read-through steps the cache is drawn and simulated as two parts: a cache service (a server model with 64 workers, each held while a request is served, including while it waits for the database) and its memory; the service checks memory, loads misses from the database and stores them. Coalescing lets misses for a key wait for a load already in flight on the cache service. The Search API and the slow-motion walk-throughs are scripted packets, not simulated traffic. A failed cache service refuses requests, and the Shop API has no fallback. The hit-ratio tile counts every lookup since the simulation started, including warm-up. Numbers show behaviour and orders of magnitude only.