Distributed Caching

A cache inside a single application process is easy — but it doesn't scale, and every instance of your app has its own separate copy. The moment you run many application servers, you want a shared cache they all use, which means a cache that lives across the network on its own machines: a distributed cache like Redis or Memcached. This unlocks scale and sharing, but introduces the distributed-systems problems that a local cache never had. Understanding distributed caching is understanding how caching works at real scale.

Distributed caching spreads a cache across multiple machines — a shared, networked cache (like Redis or Memcached) that many application servers use. This post covers why distributed caches exist, how they work (a networked shared cache), how they scale across nodes (sharding and consistent hashing), and the distributed challenges. It builds on all the prior caching concepts, now at scale across machines, and connects caching to distributed systems.

Why distributed caching

Distributed caching — a cache running on separate machine(s), shared over the network by many clients — exists to solve the limits of a local (in-process) cache at scale:

Distributed caching — a shared, networked cache on dedicated machines (Redis, Memcached) — solves the local cache’s limits (not scalable beyond one machine, not shared across app instances) by providing one shared, scalable cache for the whole system. It’s how caching works at real scale. But moving the cache across the network changes things.

How a distributed cache works

A distributed cache is a networked, shared store — which introduces differences from a local cache worth understanding:

A distributed cache works as a networked, shared, in-memory service — slower than local memory (network latency) but far faster than the source, shared across app servers (a benefit but also a dependency/bottleneck), and typically volatile (in-memory, disposable cache data). These properties differ from a local cache and shape how it’s used. Its key capability is scaling across multiple machines.

Scaling across nodes: sharding and consistent hashing

To hold more data than one machine and scale, a distributed cache spreads data across multiple nodes — via sharding, made manageable by consistent hashing:

Distributed caches scale by sharding (splitting data across nodes to hold more and spread load), made practical by consistent hashing (adding/removing a node moves only a small fraction of keys, not almost all — avoiding the massive rehashing of naive modulo sharding). Consistent hashing is the foundational technique enabling elastic distributed caches. Scaling across machines brings distributed-systems challenges.

Distributed caching challenges

Distributing the cache across machines introduces the distributed-systems challenges a local cache never had — worth knowing:

Distributed caching — a shared, networked cache (Redis, Memcached) scaled across nodes via sharding and consistent hashing — solves local caches’ scale and sharing limits but introduces distributed-systems challenges (network latency/failure, harder consistency, the cache as critical infrastructure). It’s how caching works at real scale, at the intersection of caching and distributed systems. Next: web and CDN caching — caching across the internet.

Key takeaways

Further reading

Sources & References

A distributed cache/data store
Scaling caches across nodes