12 Comments
User's avatar
Nic's avatar

I think the diagram is just missing the pros and cons of each strategy.

Expand full comment
Akshay Baura's avatar

**Write-through**: data is written in cache & DB; I/O completion is confirmed only when data is written in both places

**Write-around**: data is written in DB only; I/O completion is confirmed when data is written in DB

**Write-back**: data is written in cache first; I/O completion is confirmed when data is written in cache; data is written to DB asynchronously (background job) and does not block the request from being processed

Expand full comment
Andrey Aktanorovich's avatar

What does "IO completion confirmed" mean?

Is the cache connecting to the DB or what interaction is implied?

Expand full comment
Akshay Baura's avatar

It implies when your application gets an ACK for the write operation completion.

Expand full comment
Pham Hai's avatar

I saw a lot of tech blog on the internet about caching strategies. And most of it said that in write through strategy, data was save to cache layer first and save to data source after that. Can you explain why?

Expand full comment
gigas's avatar

This is the data flow of write through pattern by design, what do you mean WHY?

Expand full comment
truonglx's avatar

How can you share to choose best case to apply strategies

Expand full comment
onur's avatar

When to use what? The best strategy depends on your use case:

Cache-Aside: Good for read-heavy workloads where data updates can be slightly delayed.

Read-through: Simpler setup when reads significantly outweigh writes.

Write-through: Ensures strong consistency between the cache and the database.

Write-back: Prioritizes fast writes, risks some inconsistency if the cache fails before data is flushed.

Write-around: Useful for data that's infrequently read or doesn't need immediate caching.

Expand full comment
Duck Dickson's avatar

Thanks for this post! Can you also comment on Write-behind? Also, I agree with the prior commenter that this should talk a little about pros and cons.

Expand full comment
Juliano Sena da Silva Carlos's avatar

What is the difference between Cache Aside and Write Around? I know You've answer below, but, I didn't get, Could you elaborate on that more?

Expand full comment
whitetiger's avatar

What is the difference between write-around and cache-aside? They both seem very similar.

Expand full comment
dsmhitsz's avatar

write strategy and read strategy

Expand full comment