Mastering Cache Strategies: From CDN to Distributed Systems

This article provides a comprehensive overview of caching in large distributed systems, covering theory, common components, classification, CDN and reverse‑proxy caches, local application caches, popular implementations like Ehcache, Guava, Memcached and Redis, and a detailed comparison of their features and trade‑offs.

IT Architects Alliance
IT Architects Alliance
IT Architects Alliance
Mastering Cache Strategies: From CDN to Distributed Systems

Cache Overview

Caching stores frequently accessed data closer to the consumer, reducing latency, off‑loading backend resources, and improving overall system throughput in large distributed environments.

Cache Classification

Cache implementations can be grouped into four major categories:

CDN Cache

Basic introduction : A Content Delivery Network (CDN) deploys cache nodes in geographically distributed points of presence (PoPs). Global load‑balancing routes user requests to the nearest healthy cache node, which serves static assets directly.

Typical use cases : Static resources such as images, videos, CSS, and JavaScript files.

Advantages : Reduces origin server load, lowers round‑trip latency, and improves end‑user experience.

CDN cache advantages
CDN cache advantages

Reverse Proxy Cache

Basic introduction : A reverse‑proxy sits in front of application servers, intercepting all HTTP requests. If a response is cached, the proxy returns it immediately; otherwise it forwards the request to the origin, caches the response, and then serves it.

Typical use cases : Small static files (CSS, JS, images) and HTML fragments that change infrequently.

Reverse proxy cache diagram
Reverse proxy cache diagram

Local Application Cache

Basic introduction : The cache lives inside the same process as the application, providing ultra‑low latency access without network overhead. It is suitable for single‑instance services or scenarios where each node maintains an independent cache.

Advantages : Minimal latency, no network cost.

Disadvantages : Cache is tightly coupled to the application, cannot be shared across services, and may lead to memory waste.

Typical use cases : Caching dictionaries, reference data, or computed results that are read frequently.

Ehcache

Basic introduction : Ehcache is a widely used open‑source Java cache. It supports both in‑process and out‑of‑process deployments and can scale from megabytes to terabytes.

Key features :

Rich XML/Java configuration

Multiple eviction policies (LRU, LFU, FIFO, custom)

Seamless integration with Spring, Hibernate, JCache, and other frameworks

Expiration strategy : Lazy eviction stores a timestamp with each entry; on read the cache compares the current time with the configured TTL to decide if the entry is expired.

Ehcache lazy eviction
Ehcache lazy eviction

Guava Cache

Basic introduction : Part of Google’s Guava library, Guava Cache provides a lightweight in‑memory cache for Java applications.

Features :

Automatic eviction based on size or time

Refresh‑after‑write support

CacheLoader for lazy loading of missing entries

Typical use cases : Caching small‑to‑medium data sets with simple eviction requirements, such as lookup tables or computed values.

Guava cache features
Guava cache features

Distributed Cache

A distributed cache runs as an independent service that can be accessed by multiple applications, providing high availability, scalability, and centralized data sharing.

Typical use cases : Session storage, user profile caching, shared reference data, and any data that must remain consistent across services.

Memcached

Basic introduction : Memcached is a high‑performance, distributed memory object cache. It stores arbitrary binary blobs in a large hash table and relies on client‑side sharding for distribution.

Key characteristics :

LRU eviction policy

Simple key‑value store (no persistence)

Client‑side consistent hashing for horizontal scaling

Expiration strategy : Each item can be assigned a TTL; when memory is exhausted, the least‑recently‑used items are evicted first.

Memcached characteristics
Memcached characteristics

Redis

Basic introduction : Redis is an in‑memory data store that supports rich data structures (strings, hashes, lists, sets, sorted sets) and offers persistence, replication, and high‑availability via Sentinel and Cluster.

Data model : Supports multiple native types, enabling complex data modeling directly in the cache.

Eviction policies : Configurable LRU, LFU, volatile‑LRU, all‑keys‑LRU, etc., with dedicated background threads for cleanup.

Persistence : RDB snapshots and Append‑Only File (AOF) logging provide durability across restarts.

High availability : Sentinel provides automatic failover; Redis Cluster offers sharding and fault tolerance.

Redis eviction policies
Redis eviction policies

Redis vs. Memcached Comparison

Data structures : Redis supports hashes, lists, sets, sorted sets; Memcached only stores raw byte strings.

Persistence : Redis provides on‑disk persistence (RDB/AOF); Memcached does not.

High availability : Redis includes native clustering and Sentinel; Memcached requires external tooling.

Maximum value size : Redis up to 512 MiB per key; Memcached up to 1 MiB.

Memory management : Memcached pre‑allocates memory pools for deterministic allocation; Redis allocates on demand, which may cause fragmentation.

Thread model : Memcached is multithreaded; Redis runs a single‑threaded event loop (CPU‑bound operations may limit throughput).

Typical fit : Redis excels when complex data structures, persistence, or high‑availability are required; Memcached shines for simple, massive key‑value workloads with extremely high QPS.

Original Source

Signed-in readers can open the original source through BestHub's protected redirect.

Sign in to view source
Republication Notice

This article has been distilled and summarized from source material, then republished for learning and reference. If you believe it infringes your rights, please contactadmin@besthub.devand we will review it promptly.

BackendDistributed SystemsrediscachingMemcachedEhcache
IT Architects Alliance
Written by

IT Architects Alliance

Discussion and exchange on system, internet, large‑scale distributed, high‑availability, and high‑performance architectures, as well as big data, machine learning, AI, and architecture adjustments with internet technologies. Includes real‑world large‑scale architecture case studies. Open to architects who have ideas and enjoy sharing.

0 followers
Reader feedback

How this landed with the community

Sign in to like

Rate this article

Was this worth your time?

Sign in to rate
Discussion

0 Comments

Thoughtful readers leave field notes, pushback, and hard-won operational detail here.