Cache-aside vs Read-through vs Write-through vs Write-back
Learn the four common caching patterns, how reads and writes flow, their trade-offs, and when each pattern fits a real system design.
AI-generated explainer by Dilectus · · 7 min read
Caching is one of the fastest ways to reduce latency and database load, but the pattern you choose changes how data moves through your system. The main question is simple: does the application talk to the cache directly, or does the cache sit between the app and the database and manage more of the work?
The four common patterns—cache-aside, read-through, write-through, and write-back—solve the same problem with different trade-offs in speed, consistency, complexity, and failure handling.
The four patterns at a glance
A cache can be used in two broad ways:
- Application-managed: the app knows about the cache and decides when to read or write it.
- Cache-managed: the cache layer takes on more responsibility for fetching or persisting data.
Cache-aside:
Client -> App -> Cache? -> DB
| miss
v
DB -> App -> Cache
Read-through:
Client -> App -> Cache -> DB
| miss
v
DB (cache fills itself)
Write-through:
Client -> App -> Cache -> DB
write to both
Write-back:
Client -> App -> Cache -> DB (later)
ack fast, persist async
A quick comparison
| Pattern | Read path | Write path | Consistency | Write latency | Failure risk |
|---|---|---|---|---|---|
| Cache-aside | App checks cache first | App writes DB, then invalidates/updates cache | Medium | Low to medium | Stale cache if invalidation fails |
| Read-through | Cache handles misses | Usually still app or separate write path | Medium to high | Low | Cache layer is more complex |
| Write-through | Read from cache | Cache writes DB before ack | High-ish | Higher | Slower writes, but simpler reads |
| Write-back | Read from cache | Cache acks first, DB later | Lower until flush | Lowest | Data loss if cache fails before flush |
Cache-aside: the most common pattern
In cache-aside, the application is responsible for cache logic. It first checks the cache; if there is a miss, it loads from the database, stores the result in cache, and returns it.
Read flow
- App receives a request for user profile
123. - App looks in cache for
user:123. - If present, return it immediately.
- If absent, query the database.
- Store the fresh value in cache with a TTL.
- Return the value to the caller.
Write flow
- App writes the new value to the database.
- App deletes or updates the cache entry.
- Next read repopulates the cache.
This pattern is popular because it is easy to understand and works with almost any cache store. It also keeps the cache as a performance optimization, not a source of truth.
Why teams like it
- Simple mental model.
- Works well when reads dominate writes.
- Easy to scale incrementally.
- If the cache is down, the app can still hit the database.
Where it can go wrong
The biggest risk is stale data. If the database update succeeds but cache invalidation fails, readers may keep seeing old values until the TTL expires. Another common issue is the thundering herd problem: many requests miss the same hot key and all rush to the database at once.
Read-through: the cache fetches on a miss
In read-through caching, the application asks the cache for data, and the cache itself loads the value from the database on a miss. The app does not need to know whether the value came from cache or storage.
Read flow
- App requests
product:88from the cache. - Cache checks if the item exists.
- On a miss, cache loads it from the database.
- Cache stores the value.
- Cache returns the value to the app.
This is useful when you want to centralize cache logic and keep application code clean. It can also reduce duplicated cache-handling code across services.
Trade-offs
- Cleaner app code.
- Good for uniform access patterns.
- Harder to debug because the cache layer does more work.
- Cache implementation or vendor matters more.
Read-through is often paired with a cache that supports a loader function or integrated persistence adapter. The exact mechanics vary by product, but the idea is the same: the cache becomes an active data-fetching layer.
Write-through: every write goes to cache and database
In write-through caching, the app writes to the cache, and the cache synchronously writes the same data to the database before acknowledging success. Reads are fast because the cache is kept fresh on every write.
Write flow
- App updates
order:501. - Cache receives the write.
- Cache writes to the database synchronously.
- Only after the database confirms success does the cache acknowledge the write.
- Future reads can be served from cache.
This pattern improves read freshness and reduces the chance of stale cache entries. It is useful when you want cache and database to stay closely aligned.
Trade-offs
| Benefit | Cost |
|---|---|
| Stronger read freshness | Higher write latency |
| Simpler reads | More work on every write |
| Easier cache warm-up | Cache becomes part of the critical write path |
Because writes are synchronous, write-through can feel slower than cache-aside. For example, if the database write takes ~8 ms and cache write adds ~1 ms, the user sees the combined latency rather than just the faster cache step. That is still often acceptable if reads are much more frequent than writes.
Write-back: fast writes, delayed persistence
Write-back caching, sometimes called write-behind, acknowledges the write as soon as data reaches the cache and persists it to the database later, asynchronously.
Write flow
- App writes
session:abcto cache. - Cache immediately acknowledges success.
- Cache batches or queues the write.
- Background worker flushes changes to the database later.
- Database eventually catches up.
This pattern gives the lowest write latency and can absorb bursts very well. It is useful when the data is high-volume and temporary, or when the system can tolerate eventual persistence.
Risks to watch
- Data can be lost if the cache node crashes before flushing.
- Ordering becomes important if multiple updates happen quickly.
- Recovery logic is more complex.
- The database may lag behind what the app just accepted.
Write-back should be used carefully for data that matters. It is more comfortable for telemetry, counters, logs, or session-like data than for money movement or inventory.
Which pattern fits which workload?
The best choice depends on what you optimize for: read latency, write latency, consistency, or operational simplicity.
| Workload shape | Best fit | Why |
|---|---|---|
| Read-heavy product catalog | Cache-aside or read-through | Many repeated reads, occasional updates |
| Shared library of cached objects | Read-through | Keeps app code simple and consistent |
| User-facing settings or profiles | Write-through or cache-aside | Fresh reads matter, writes are manageable |
| Event counters, logs, analytics buffers | Write-back | Fast ingest and batch persistence |
| Financial or inventory data | Cache-aside or write-through, with care | Need clearer consistency boundaries |
Practical rule of thumb
- If the cache is just a speed layer, start with cache-aside.
- If you want the cache to hide fetch logic from apps, consider read-through.
- If readers must see fresh data quickly, consider write-through.
- If write latency matters more than immediate durability, and data loss is acceptable or recoverable, consider write-back.
When to use it (and when not to)
Use cache-aside when
- You want the simplest and most common pattern.
- Reads dominate writes.
- Your team wants explicit control over cache invalidation.
- The database must remain the source of truth.
Avoid it when you need very tight freshness guarantees and cache invalidation bugs would be costly.
Use read-through when
- Multiple services should share the same cache loading behavior.
- You want less cache code in the application.
- Your cache platform supports it well.
Avoid it when the cache layer becomes too opaque or vendor-specific for your team.
Use write-through when
- You want cache and database to stay closely synchronized.
- Reads are frequent and should be fresh.
- Slightly slower writes are acceptable.
Avoid it when write latency is critical or the database cannot handle every write synchronously.
Use write-back when
- You can tolerate eventual persistence.
- High write throughput matters more than immediate durability.
- The data can be replayed, rebuilt, or safely lost in rare failures.
Avoid it when losing a few seconds of data would be unacceptable.
How interviewers probe this topic
Interviewers usually want to see whether you understand not just the definitions, but the failure modes and trade-offs.
What they may ask
- How does each pattern behave on a cache miss?
- What happens if the cache and database disagree?
- How do you handle stale data?
- Which pattern would you choose for a read-heavy feed, profile page, or counter?
- What breaks if the cache goes down?
How to answer well
A strong answer usually follows this structure:
- State the workload shape: read-heavy, write-heavy, freshness needs, durability needs.
- Pick a pattern and explain why.
- Mention the main failure mode.
- Add one mitigation: TTL, invalidation, retries, batching, or fallback to DB.
For example: “For a product detail page, I’d start with cache-aside because reads are frequent and the database remains the source of truth. I’d use TTL plus explicit invalidation after updates, and I’d protect hot keys with request coalescing to avoid a stampede.”
Key takeaways
- Cache-aside is the default choice when you want simple, app-controlled caching.
- Read-through moves cache-miss loading into the cache layer and reduces app-side code.
- Write-through keeps cache fresh but adds synchronous write latency.
- Write-back gives the fastest writes, but durability becomes eventual and failure-prone.
- The right pattern depends on the balance between freshness, latency, and risk.
- In interviews, always mention the failure mode and one mitigation, not just the definition.
Frequently asked questions
- Is cache-aside the same as lazy loading?
- Yes, in practice they are closely related. The application loads data into the cache only after a miss, so the cache fills lazily instead of being preloaded.
- Can a system use more than one caching pattern?
- Yes. A common setup is cache-aside for most reads, with write-through for a few critical entities. Real systems often mix patterns based on data type and freshness needs.
- What is the biggest mistake teams make with caching?
- Treating the cache like a database. A cache is usually an acceleration layer, so missing invalidation, bad TTLs, or no fallback path can create stale reads or outages.
- When should I prefer write-through over cache-aside?
- Prefer write-through when read freshness matters a lot and you can afford slower writes. It is useful when you want the cache to stay synchronized without relying on separate invalidation logic.

