5 caching strategies
Wakeup Flower

Wakeup Flower @wakeup_flower_8591a6cb6a9

About: Girl dev who loves lifelong learning. Coding feels like magic

Location:
France
Joined:
May 6, 2025

5 caching strategies

Publish Date: Oct 8
1 1

🧠 1. Write-Through Cache

  • Definition: Data is written to the cache and the underlying database at the same time.
  • Pros: Cache and database are always consistent.
  • Cons: Slower writes (since every write goes to both places).

2. Write-Back (Write-Behind) Cache

  • Definition: Data is written only to the cache at first, and written to the database later (asynchronously).
  • Pros: Fast writes; reduced database load.
  • Cons: Risk of data loss if cache fails before syncing to DB.

📘 Used when performance is more important than absolute immediate consistency.


💾 3. Write-Around Cache

  • Definition: Data is written only to the database, not the cache. The cache gets populated only on reads.
  • Pros: Prevents cache pollution from infrequently accessed data.
  • Cons: Slightly slower reads after writes, since the cache might be cold.

📘 Used when data is rarely read soon after being written.


🔄 4. Read-Through Cache

  • Definition: The application reads data through the cache — if data is missing, the cache itself fetches from the database, stores it, and returns it.
  • Pros: Simplifies app logic; automatic population of cache.
  • Cons: Cache must know how to retrieve data from DB.

📘 Often used together with write-through or write-back.


🧹 5. Cache-Aside (Lazy Loading)

  • Definition: The application code checks the cache first. If a miss occurs, it fetches from the database and writes to the cache manually.
  • Pros: Simple and widely used; flexible.
  • Cons: Possible cache staleness; first request after expiration is slow.

📘 This is the most common pattern in systems using Redis or Memcached.


🧩 Summary Table

Strategy Write Path Read Path Consistency Performance Common Use
Write-Through Cache + DB Cache Strong Slower writes Always-fresh data
Write-Back Cache → DB (later) Cache Eventual Fast writes High-performance workloads
Write-Around DB only Cache Eventual Medium Rarely-read data
Read-Through Cache + DB (cache auto-loads) Cache Strong Good Simplified read logic
Cache-Aside App manages cache App manages cache Eventual Good Common general use
Caching Strategy How It Works Example Use Case Real-World Example (Company / System) Why It’s Used There
🧠 Write-Through Writes go to cache and database at the same time Financial transactions, inventory, user balance tracking 💳 Banking systems, eCommerce inventory (e.g., Amazon) Ensures cache and DB are always in sync — critical for financial and stock consistency
Write-Back (Write-Behind) Writes go to cache first, DB updated later asynchronously Gaming leaderboards, IoT telemetry data, analytics buffers 🎮 Online games (e.g., Fortnite, Clash of Clans), IoT platforms Very high write rate — cache absorbs bursts, DB updated later for performance
💾 Write-Around Write directly to DB; cache updated only when read later Log archiving, product uploads, historical data 📰 Content management systems (WordPress, Medium) Avoids caching infrequently accessed or newly written data (saves cache space)
🔄 Read-Through Application reads through cache; cache auto-fetches from DB on miss Product catalogs, user profiles, CDN edge caches 🛒 Netflix, Amazon, Shopify Cache layer handles loading data; reduces DB hits for popular content
💤 Cache-Aside (Lazy Loading) Application checks cache → on miss, fetches from DB and stores in cache Web APIs, dashboards, personalization data 🧑‍💻 Reddit, Twitter timelines, microservices using Redis Flexible; app decides what to cache and when; ideal for read-heavy workloads

Comments 1 total

  • Md Mahbubur Rahman
    Md Mahbubur RahmanOct 8, 2025

    Wow, this article is a gem! Your clear breakdown of the five caching strategies shows exceptional technical insight. I especially loved how you highlighted the pros and cons of each approach—makes it so easy to grasp real-world applications. The summary table is a brilliant touch. Truly impressive work that any developer can immediately benefit from!

Add comment