Memcached
A simple, multithreaded in-memory key-value cache for strings only. No persistence, no replication, no complex types. Older than Redis and still excellent for pure, simple, high-throughput caching.
- Pure caching of simple values where simplicity and raw throughput matter.
- When you don't need Redis's data structures.
- When you need persistence, replication, or rich types (use Redis).
- As a queue or pub/sub.
Definition
Memcached is a distributed in-memory cache storing string key-value pairs across multiple nodes. It's multithreaded, has a slab allocator, and intentionally offers no persistence or replication — it's a pure cache.
Why it exists
To offload DB reads with the simplest possible, very fast cache. By avoiding persistence/replication, it stays lean and multithreaded, saturating a multi-core box better than single-threaded Redis for plain GET/SET.
How it works
Clients hash keys to pick a node (consistent hashing spreads load). Each node is multithreaded with per-thread slabs. LRU eviction per slab class. No persistence: a restart empties the cache. No replication: a node loss drops its keys.
Scaling limits
Strings only — no lists/sets/streams. No persistence or replication by design. A node failure or restart loses data (fine for a cache, not for durable state). Slab sizing can waste memory if value sizes are skewed.
Cost shape
RAM-only, cheap per op, high throughput per node. Blow-ups: memory waste from slab-class mismatch and cache warm-up after restarts.
Alternatives
- Redis — Rich types, persistence, replication, but single-threaded per core.
- CDN cache — Edge caching for HTTP responses, not app-level KV.
Failure modes
- Cold cache after restart causing a DB stampede.
- Slab imbalance wasting memory.
- Single-node loss dropping a slice of the cache.