liveBook · Manning

Distributed caching

As explained in Advanced Algorithms and Data Structures

A distributed cache is a cache partitioned across multiple processes or nodes that coordinate request routing and data storage.

A single-process cache can become ineffective when request volume or cached data exceeds one machine’s practical capacity. Distributed caching spreads entries across standalone cache nodes and routes each request to the node responsible for its key. section 7.8 section 7.3

The design separates responsibilities:

  • Nodes store cache entries independently. section 7.8
  • An orchestrator routes requests to the appropriate node. section 7.8
  • Consistent hashing maps keys and nodes into the same identifier space, assigning each key to the next node. section 7.8
  • Adding or removing a node remaps only a fraction of keys instead of forcing a complete redistribution. section 7.8

Scaling cached database results

At roughly a million database accesses per second, a cache limited to one process may provide too little protection. Splitting entries across nodes increases capacity, while consistent hashing limits disruption when the cluster changes. section 7.8

Figure 7.14 An array of cache nodes using consistent hashing for distributing keys. On the left, the initial nodes array. Nodes and keys map to the same metric space (the IDs space), usually represented as a circle (which could be obtained even with just a modulo operation on the hash values). Keys are assigned to the next node in the circle—that is, the node whose value is the smallest node’s ID larger than the key’s hashing. On the right, we can see how, when a cache node is removed or added, only a fraction of the keys needs to be remapped.

Follow the key-and-node ring to see how consistent hashing assigns entries and preserves most assignments after a node is added or removed. section 7.8

How Advanced Algorithms and Data Structures covers it

How deep it goes
Explains nodes, routing, consistent hashing, and limited remapping, but stops short of cache implementation details.
Examples
Uses database results, billion social-media walls, high request rates, and a consistent-hashing node-ring figure.
What it assumes
Assumes basic caching and database concepts while motivating the transition from a single-process cache to a distributed design.
What you can do after
Evaluate distributed-cache layouts and understand how consistent hashing limits reassignment during node changes.
How it connects
Connects caching with consistent hashing, orchestrators, cache nodes, database systems, and NoSQL databases.

Also explained in

Compare how 4 books explain distributed caching →

Related concepts

This explainer was generated by Manning's knowledge graph from the text of Advanced Algorithms and Data Structures. The section links point to the parts of the book it draws on.