Spread a cache over many machines (like Redis or Memcached) so it can grow and survive failures.
A distributed cache spreads cached data over many machines. Together they act like one big, fast memory shared by all your app servers.
A cache on one app server only helps that server. If you run 20 app servers, they would each keep their own copy, waste memory, and show different data. A distributed cache is one shared cache that all app servers use over the network.
| Point | Memcached | Redis |
|---|---|---|
| Data types | Simple key and value (strings) | Strings, lists, sets, sorted sets, hashes and more |
| Replication | Not built in | Built in (a primary and replicas) |
| Saving to disk | No, memory only | Optional (snapshots, append log) |
| Clustering | Done by the client (it picks the node) | Redis Cluster splits keys into slots across nodes |
| Threads | Multi-threaded | Mostly one main thread for commands (newer versions add some I/O threads) |
| Good for | A plain, fast cache | Cache plus counters, queues, leaderboards, sessions |
Redis Cluster uses a related idea: 16,384 fixed hash slots split among the nodes. Moving a slot moves only that slotโs keys. Read more in Consistent Hashing.
| Style | How it works | Good and bad |
|---|---|---|
| Client-side | The client library knows all nodes and picks one | No extra hop. Every client must know the topology. |
| Proxy-based | A proxy sits in front and routes requests | Clients stay simple. The proxy is one more thing to run and to make highly available. |
| Server-side redirect | Any node can answer โask node B insteadโ | Used by Redis Cluster (MOVED replies). Smart clients cache the map. |
k#1, k#2). A big key (a huge list) slows its node. Keep values small or split them.| Term | Meaning in easy words |
|---|---|
| Node | One cache server in the group |
| Shard / partition | A slice of the keys that lives on one node |
| Replica | A copy of a shard on another node |
| Primary | The node that takes writes for a shard |
| Failover | Switching to a replica when the primary fails |
| Consistent hashing | A way to map keys to nodes so few keys move when nodes change |
| Hash slot | One of a fixed number of buckets of keys (Redis Cluster uses 16,384) |
| Hot key | A key that gets far more requests than others |
| Big key | A key with a very large value |
| Eviction | Removing items when memory is full |
| Hit ratio | The share of reads served from the cache |
| Split brain | Two nodes both think they are the primary |
| Choice | We gain | We lose |
|---|---|---|
| Replication on | Failover, no cold cache after a crash | More memory, copies can lag behind |
| Replication off | Cheaper, simpler | A crash loses data and floods the DB |
| Consistent hashing | Few keys move when nodes change | More complex than modulo |
| Client-side routing | No extra hop | Every client needs the node list |
| Proxy routing | Simple clients | An extra hop, another system to run |