Caching Strategies & CDN Design

Design caches that stay fast and correct: cache-aside, invalidation, stampedes, eviction, Redis, HTTP Cache-Control and ETags, and CDN keys and purging.

Start course →

What you'll learn

  • Decide what, where and how long to cache using hit ratio, working set and staleness requirements.
  • Implement cache-aside, read-through, write-through and write-behind patterns with sensible TTLs.
  • Invalidate caches reliably with deletes, versioned keys, tags and change data capture, and avoid race conditions.
  • Prevent stampedes, avalanches, penetration and hot-key overload, and choose eviction policies.
  • Write correct HTTP caching headers with Cache-Control, ETags, Vary and stale-while-revalidate.
  • Design CDN caching with good cache keys, purging, micro-caching, edge security and safe handling of private data.

Syllabus

Why and Where to Cache

  1. What Caching Buys You
  2. Caching Layers from Browser to Database
  3. Hit Ratio, Effective Latency and the Working Set

Read and Write Patterns

  1. Cache-Aside (Lazy Loading)
  2. Read-Through, Write-Through, Write-Behind and Write-Around
  3. TTLs, Refresh-Ahead and Negative Caching

Invalidation and Consistency

  1. Why Invalidation Is Hard
  2. Invalidation Strategies
  3. Race Conditions and Stale Sets

Failure Modes Under Load

  1. Cache Stampede and Request Coalescing
  2. Cache Avalanche and Cache Penetration
  3. Hot Keys and Big Keys

Eviction and Distributed Caches

  1. Eviction Policies
  2. Redis, Memcached and Cache Clusters
  3. In-Process and Two-Level Caches

HTTP Caching

  1. Cache-Control and Friends
  2. Validation: ETag, Last-Modified and Vary
  3. Stale-While-Revalidate, Stale-If-Error and Asset Fingerprinting

CDN Design

  1. How CDNs Work
  2. Cache Keys and Purging
  3. Dynamic Content, Edge Compute and Security

Operating Caches, Security and Revision

  1. Monitoring and Testing Caches
  2. Caching and Security
  3. Case Study: Caching an E-Commerce Catalogue
  4. Revision and Interview Questions