Cloud Parts

In-process cache, shared cache or CDN?

DimensionIn-process cachesCachingCDNs
Where it livesInside each service instance’s own memorySeparate cache servers on your network (Valkey, Redis, Memcached)Edge servers near users, in front of your origin
Who shares itOne process only; ten pods means ten separate cachesEvery instance of every service that connects to itEvery user routed to that edge location
Cost of a hitA memory lookup: nanoseconds to microseconds, no networkSub-millisecond on the server, plus a network round tripA round trip to the nearest edge instead of to your origin
What it storesLive objects in your language’s own typesSerialised values under keysWhole HTTP responses: pages, images, scripts, API replies
How entries go staleTTL and size limit per instanceTTL per key (SET … EX), or delete the key when the source changesCache-Control max-age or s-maxage from the origin, or a default TTL (24 hours on CloudFront without a cache policy)
InvalidatingHard: each instance must be told, or waits out its TTLEasy: one place to delete or overwrite the keyA purge or invalidation API; CloudFront recommends versioned file names for frequent updates
CapacityCounts against each pod’s memory limit; too big and the pod is OOMKilledThe cluster’s RAM; add nodes or shards to growLarge and managed by the provider; rarely requested files are evicted
After a deploy or restartEmpty; every new instance warms up from scratchStill warm; it runs apart from the appStill warm; deploys of the origin don’t touch it
ExamplesCaffeine, Guava, lru-cache, functools.lru_cache, .NET IMemoryCacheValkey, Redis, Memcached; ElastiCache, Memorystore, Azure Managed RedisCloudFront, Cloud CDN, Azure Front Door, Cloudflare

Rule of thumb

They stack rather than compete. A typical read path is CDN for public HTTP responses, then an in-process cache for the few hottest objects, then a shared key-value cache that all instances agree on, then the database. Put data in the layer whose staleness you can live with: an in-process copy can be out of date per instance for its whole TTL, a shared cache can be fixed with one delete, and a CDN copy lasts until its max-age or a purge.

Sources