🔴 Redis Intermediate

What is the cache-aside pattern vs write-through caching?

Answer

Cache-aside (lazy loading): the application checks Redis first; on a miss, it reads from the database and writes the result into Redis before returning it. The cache is populated on demand. Pros: only requested data is cached, cache is small. Cons: the first request always hits the database (cold start), and cache and database can be briefly inconsistent. Write-through: every write goes to the cache and the database simultaneously (or the cache proxies the database write). Pros: cache is always consistent with the database; no cold-start miss. Cons: every write is slower (two writes), and infrequently read data wastes cache space. Write-behind (write-back): writes go to the cache first and are asynchronously written to the database later — fastest writes but risk of data loss if the cache crashes before syncing. Cache-aside is by far the most common pattern in practice.