SDI.
All Concepts
Cachingperformancelatencycache-invalidationredismemcachedCDNwrite-throughwrite-back

Caching

Caching stores copies of frequently accessed data in a faster storage layer to reduce latency, lower database load, and improve throughput.

Caching places a copy of hot data in a fast store (RAM, SSD, edge node) so future reads skip the slower origin. The biggest challenge is cache invalidation — keeping cached data consistent with the source of truth. Common strategies are cache-aside (app checks cache first, fills on miss), write-through (writes go to cache and DB simultaneously), and write-back (writes go to cache first, DB later). Redis and Memcached are the most widely deployed in-memory caches.

Tradeoffs

Strengths

  • Dramatic latency reduction: 100–1000× faster than database reads for in-memory caches.
  • Database offloading: A well-tuned cache can absorb 90–99% of read traffic, extending DB life.
  • Cost efficiency: RAM is more expensive per GB than disk, but the reduction in DB instances and compute often makes caching a net cost saver.
  • Scalability: Caches scale horizontally with consistent hashing, supporting millions of ops/sec.

Weaknesses

  • Consistency complexity: Stale data is the default unless you invest in invalidation infrastructure.
  • Operational overhead: Running a distributed cache cluster (monitoring, failover, memory management) requires dedicated effort.
  • Cold start vulnerability: After a deploy, restart, or failover, the empty cache can overload the database.
  • Memory cost at scale: Caching large datasets (e.g., full user profiles) can require terabytes of RAM.
  • Cache penetration: Queries for non-existent keys always miss the cache and hit the DB. Mitigation: cache null results with short TTL, or use a Bloom filter.
  • Added complexity: Every data path now has two sources of truth, increasing debugging difficulty.

Likely Follow-Up Questions

  • How would you handle cache invalidation in a microservices architecture where multiple services write to the same data?
  • What is the thundering herd problem and how do you mitigate it?
  • When would you choose Memcached over Redis, and vice versa?
  • How do you decide the TTL for a cache entry?
  • What is cache stampede and how does request coalescing solve it?
  • How would you design a multi-tier caching strategy for a global application?

Source: editorial — Synthesized from Redis/Memcached documentation, Facebook Memcache NSDI 2013 paper, and industry best practices.

Command Palette

Search for a command to run...