Black Friday: 30% off every plan through November 30. See the prices
SysDesignPrep.com
Study guide

Updated 24 October 2026

Redis vs Memcached

Choosing an in-memory store: Redis and Memcached compared on data structures, threading, persistence, replication, clustering, eviction, memory efficiency and operations, with guidance on when a plain cache is enough and when you need Redis features.

Reading is half of it. Now try it in an interview.An AI interviewer asks you to design a Distributed Cache, out loud or typed, and scores the answer for your level. Or watch a sample interview first, free with no sign-up to start.
Start an AI mock

Try it yourself, in a playground:Cache write policiesCache sizing

Both Redis and Memcached keep data in memory and answer in well under a millisecond, and both appear in designs as "the cache". They are not interchangeable: Memcached is a deliberately simple, multithreaded key-value cache, while Redis is a single-threaded-at-its-core server of data structures with persistence and replication. Interviewers occasionally ask which you would choose; the answer depends on whether you need more than get and set.

Memcached

  • Strings only: keys map to opaque byte values, up to 1 MB by default.
  • Multithreaded: uses all cores on a large machine efficiently.
  • No persistence and no replication: a restarted node is empty; data loss is expected.
  • Client-side sharding: clients hash keys to servers (usually with consistent hashing); servers do not know about each other. See consistent hashing.
  • Slab allocator with LRU eviction per slab class: predictable memory, little fragmentation.
  • Very simple to run.

Facebook famously scaled Memcached to enormous fleets for look-aside caching of database queries.

Redis

  • Rich data structures: hashes, lists, sets, sorted sets, streams, HyperLogLog, geo indexes, bitmaps. See Redis data structures.
  • Server-side operations: increments, rank queries, set intersections and Lua scripts execute atomically in the server.
  • Persistence: snapshots and append-only logs.
  • Replication to replicas with automatic failover (Sentinel or Cluster).
  • Redis Cluster shards keys across nodes with hash slots.
  • Pub/sub and streams for messaging.
  • Command execution is single-threaded per instance (with I/O threads in newer versions), so you scale by running more shards. Forks (Valkey) and compatible alternatives (KeyDB, Dragonfly) exist, some multithreaded.

Comparison

MemcachedRedis
Data modelstringsmany data structures
Atomic server-side logicincrement, compare-and-setmany commands plus Lua scripts
Threadingmultithreadedsingle-threaded command execution per shard
Persistencenonesnapshots, append-only log
Replication and failovernone built inbuilt in
Shardingclient-sideRedis Cluster or client-side
Memory efficiency for small stringsvery goodgood, more per-key overhead
Use beyond cachingnoleaderboards, rate limiters, queues, sessions, locks
Operationssimplestmore features, more to configure

When Memcached is enough

  • A pure look-aside cache of database rows, rendered fragments or API responses.
  • Values are blobs you get and set whole.
  • Losing the cache is acceptable (it refills from the database).
  • You want maximum throughput per machine with minimal operations.

See caching.

When you need Redis

  • Leaderboards with sorted sets. See Design a Leaderboard.
  • Rate limiters with atomic scripts. See Design a Rate Limiter.
  • Capped timelines and feeds with lists or sorted sets. See Design a News Feed.
  • Sessions that should survive restarts, with replication.
  • Counters, unique counts, geospatial queries, delayed queues and pub/sub.
  • Any case where you would otherwise read, modify and write back a blob from many servers concurrently.

Shared concerns

Both need the same caching discipline:

  • TTL and eviction policy chosen deliberately (LRU or LFU), with memory sized for the working set.
  • Stampede protection for hot keys that expire: request coalescing, early refresh, jittered TTLs.
  • Hot keys that overload one shard: local caching or replicated keys. See hot keys and skew.
  • Invalidation on writes. See cache invalidation.
  • Neither is a database of record for data you cannot lose, even with Redis persistence.

In the interview

"We use Redis because we need sorted sets for the leaderboard and atomic counters, with replicas for failover; data can be rebuilt from the database if lost." Or, for a pure cache: "Memcached or Redis both work; it is a look-aside cache of rendered results with TTLs, sharded with consistent hashing." For Design a Distributed Cache, explain the internals either way: hashing, eviction, replication choices and hot-key handling.

Checklist

  • Memcached for simple, high-throughput, loss-tolerant caching.
  • Redis when you need data structures, atomic server-side logic, persistence or replication.
  • Eviction, TTLs and memory sized to the working set.
  • Stampede and hot-key protection.
  • The database remains the source of truth.

Questions people ask

What is the difference between Redis and Memcached?

Memcached is a deliberately simple, multithreaded key-value cache of strings, while Redis is a server of data structures, single-threaded at its core, with persistence and replication. Memcached has no persistence or built-in replication and relies on client-side sharding; Redis adds hashes, lists, sets, sorted sets and streams, atomic server-side commands and Lua scripts, snapshots and append-only logs, and Redis Cluster. Both keep data in memory and answer in well under a millisecond.

When is Memcached better than Redis?

Memcached is enough for a pure look-aside cache of database rows, rendered fragments or API responses, where values are blobs you get and set whole and losing the cache is acceptable because it refills from the database. It suits cases that want maximum throughput per machine with minimal operations, because it is multithreaded and very simple to run. Once the design needs more than get and set, Redis is the better choice.

When do you need Redis instead of Memcached?

You need Redis when the design relies on its data structures or atomic server-side logic: leaderboards with sorted sets, rate limiters with atomic scripts, capped timelines and feeds, sessions that should survive restarts, counters, unique counts, geospatial queries, delayed queues and pub/sub. It also fits any case where many servers would otherwise read, modify and write back the same blob concurrently.

Is Redis single-threaded?

Redis command execution is single-threaded per instance, with I/O threads in newer versions, so you scale it by running more shards. Memcached, by contrast, is multithreaded and uses all the cores of a large machine efficiently. Forks such as Valkey and compatible alternatives such as KeyDB and Dragonfly exist, and some of them are multithreaded.

Can you use Redis as a primary database?

No: neither Redis nor Memcached should be the database of record for data you cannot lose, even with Redis persistence. Redis does offer snapshots, append-only logs and replication with automatic failover through Sentinel or Cluster, so sessions can survive restarts, whereas a restarted Memcached node is empty. The database remains the source of truth, and anything cached should be rebuildable from it.

How do Redis and Memcached shard data?

Memcached uses client-side sharding: clients hash keys to servers, usually with consistent hashing, and the servers do not know about each other. Redis can be sharded client-side as well, or use Redis Cluster, which shards keys across nodes with hash slots. Because Redis executes commands on a single thread per shard, scaling it for throughput means running more shards.