Vibe Engines
YouTube

Vibe Engines is free, interactive AI engineering & system design — runs in your browser. Pick a learning path

Handbooks  /  Redis vs Memcached
Engineering~8 min readComparison
Head to Head

Redis vs Memcached: a cache, or a toolbox?

RedisvsMemcached

Both put data in RAM by a key and return it fast, so they look interchangeable. The split is scope: Memcached does one thing — a blazing, simple key-value cache — while Redis is a data-structure server that also caches. If all you need is caching, the simpler tool may win; the moment you need more than get/set, Redis pulls away.

01

The core difference: one job vs many

Memcached is a deliberately minimal, multithreaded key-value cache: strings in, strings out, evicted under memory pressure, no persistence, no bells. That simplicity makes it lean and easy to scale for one job — caching. Redis is a data-structure server: alongside strings it offers lists, sets, sorted sets, hashes, streams, bitmaps and more, plus persistence, replication, pub/sub, transactions, Lua scripting and clustering. It caches too — but it does far more.

→ The rule

Only need a simple, huge, cheap cache for strings/objects? Memcached is lean and fine. Need data structures, persistence, pub/sub, leaderboards, rate limiters, queues, or anything past get/set? Redis — which is why it’s the default for most teams today.

02

Head to head

DimensionRedisMemcached
Data typesStrings, lists, sets, sorted sets, hashes, streams…Strings (opaque blobs) only
ThreadingMostly single-threaded core (very fast)Multithreaded
PersistenceYes (RDB snapshots, AOF log)No — purely in-memory
Replication / HAYes (replicas, Sentinel, Cluster)No built-in replication
Pub/Sub & streamsYesNo
EvictionConfigurable policies (LRU, LFU, TTL…)LRU
Memory efficiencyGood; slight overhead for structuresVery lean for plain key-value
Best fitCache + data store + messagingSimple, large-scale caching
03

When to use each

Reach for Redis

  • Leaderboards (sorted sets), counters, rate limiters
  • Sessions or data you can’t afford to lose (persistence)
  • Pub/sub, streams, lightweight queues
  • Anything richer than string get/set
  • You want one tool for cache + more

Reach for Memcached

  • Pure caching of strings/serialized objects
  • Very large, simple caches where leanness matters
  • Multithreaded throughput on big multi-core boxes
  • You explicitly want minimal features/ops surface
  • Cache loss is harmless (regenerate on miss)
→ The honest default

Most teams pick Redis today — it does everything Memcached does and grows with you, so you rarely regret it. Choose Memcached deliberately when the workload is strictly simple caching and its lean, multithreaded model is a measured win.

04

Why the threading models differ — and why it matters less than people think

Memcached is multithreaded at the core: multiple worker threads share one big hash table, guarded by fine-grained striped item locks rather than one global lock, so on a 32-core box it can genuinely use many cores for raw get/set throughput. Redis's core command execution is single-threaded — one thread runs your GET, LPUSH or ZADD at a time, which is precisely what makes every Redis command atomic with no locking, no race conditions, no partial writes visible to another client. Redis 6+ added I/O threads to parallelize the cheap work of reading bytes off the socket and parsing the protocol, but command execution itself stays single-threaded.

In practice this rarely matters. A single Redis core can push hundreds of thousands of simple operations per second — memory bandwidth and network I/O become the bottleneck long before the single-threaded execution model does. Memcached's multithreading only shows a real edge at extreme concurrency on very large multi-core machines doing nothing but plain key-value gets — exactly the narrow case where Memcached's minimalism was designed to win. For anything with mixed operation types, larger values, or data structures, Redis's single-threaded simplicity is a feature: no lock contention, no torn writes, and command behavior you can reason about without thinking about interleaving.

→ The trade you're actually making

Multithreading buys Memcached raw throughput ceiling on simple workloads. Single-threading buys Redis atomicity guarantees for free — every command, including multi-step ones like ZADD then ZRANGE, executes without another client's command interleaving mid-way.

05

A worked scenario: building a leaderboard

Say you need a live leaderboard for 2 million players, updated on every game and read constantly for "top 100" and "my rank." With Memcached, there's no native ranked structure — you'd fetch the entire score set into your application, sort it in-memory, and re-cache the sorted result, or maintain your own auxiliary ranking system in a real database and use Memcached only to cache the rendered page. Either way, a single score change means recomputing or invalidating a chunk of that cached structure, and "what's my rank right now" is expensive to answer freshly.

With Redis, a leaderboard is a ZADD leaderboard <score> <player> away from existing as a first-class sorted set. ZRANGE leaderboard 0 99 REV returns the top 100 in O(log N + 100) time. ZRANK leaderboard player123 returns any player's live rank in O(log N). No batch recomputation, no cache invalidation dance — the data structure is the answer, kept correct automatically as scores update. This is the concrete shape of "Redis is a data-structure server": the leaderboard isn't a caching problem bolted onto a database, it's a native operation.

→ The pattern generalizes

Rate limiters (sliding-window counters), unique-visitor tracking (HyperLogLog), job queues (lists with blocking pops), and "who's online" (sets with TTL) all follow the same shape: Memcached would need the feature built in application code on top of a plain cache; Redis has the primitive already.

06

Common mistakes

MistakeWhy it bites
Treating Redis persistence as a database backupRDB/AOF protect against a restart losing the cache, not against needing point-in-time backups, cross-region durability, or transactional guarantees a real primary database provides. Redis persistence is "don't lose it on restart," not "this is now your system of record."
Storing large blobs as single Memcached valuesMemcached has a default 1MB value size limit and no partial-update support — updating one field of a large cached object means re-serializing and re-sending the whole thing. Redis hashes let you update individual fields without touching the rest.
Assuming Redis Cluster gives you what a single Redis instance gives youMulti-key operations (transactions, certain Lua scripts) only work reliably when all keys hash to the same cluster slot. Teams that scale from single-node Redis to Cluster without checking this hit surprising CROSSSLOT errors in production.
Running Memcached expecting durabilityA Memcached restart, deploy, or OOM-kill empties the cache instantly and completely — every request becomes a cache miss at once. If that stampede would hurt (thundering herd on your database), you need warming/staggering logic Redis's persistence would have avoided needing.
The picture

The picture: who decides where a key lives

Memcached Redis app + client libhash(key) → node node AN threads node BN threads node C downits keys miss no replication, no disk nodes never talk to each other app + clientZADD, INCR, GET primary1 command thread replica (async) AOF / RDB
The two systems put the intelligence in different places. In Memcached the client owns distribution: its library hashes the key to choose a node, and the nodes are independent stores that never coordinate. That keeps each server simple and lets one process spread work across many threads, but a lost node takes its share of keys with it, and the only recovery is refilling from the database. How the client hashes matters too. With plain hash(key) mod n, growing from 3 nodes to 4 sends about three keys in four to a different node, a near-total cache flush. Consistent hashing, which mainstream Memcached clients offer, moves only about a quarter: the keys the new node takes over. Redis puts more in the server. One primary runs every command for its keys on one thread, which is what makes each command atomic. It then copies writes to a replica and to disk after acknowledging them. Redis Cluster adds sharding on top, with the servers themselves tracking which node owns which slot.
Trade-offs

Cost and trade-offs: the same job on each system

Here Time is what the job costs on Redis and Space what it costs on Memcached. Each row is a real request an application makes, not a feature checkbox. Where a row says “tie”, the choice does not matter for that job.

CaseTimeSpaceWhy
Read or write one cached valueGET / SET, O(1)get / set, O(1)Both are memory- and network-bound, as the page says. Choose on the rows below, not this one.
Expire a session after inactivityEXPIRE on each request; PERSIST removes the TTLA TTL set on write; touch extends it without re-sending the valueAnother tie. Both expire per key, so a plain sliding session never forces the choice.
Count eventsINCR, O(1), atomicincr, O(1), atomic on a numeric valueA tie. The gap opens one step later: a per-window count with its own expiry, or a ranked count, is a sorted set on Redis and application code on Memcached.
Change one field of a cached userHSET on that field, O(1)Fetch the whole blob, edit it, write it back. Make it safe with a gets / cas retry loopUnder contention the CAS loop retries, and every retry moves the whole object over the network again.
Top 100 of 2 million playersZRANGE … REV, O(log N + 100): about 121 stepsFetch all scores and sort in the app: about 42 million comparisons per re-sortThis is the page’s leaderboard scenario in numbers. The cost of the Memcached version grows with the whole set, not with the answer.
Queue a jobLPUSH plus a blocking BRPOP, O(1)append can grow a value, but nothing pops or blocksNo pop means no queue. A worker would have to poll and rewrite the value.
Debit one key, credit another, all or nothingMULTI / EXEC, or one Lua script that runs as a single commandNo multi-key transaction; cas protects one item at a timeA crash between the two writes leaves Memcached half-updated. Your code has to detect and repair it.
Count unique visitors per dayPFADD / PFCOUNT: a HyperLogLog of at most 12 KB per key, about 0.81% standard errorKeep the set of ids yourself, or a sketch serialised into a value and rewritten on every visitRedis trades exactness for a fixed, tiny footprint. Memcached gives you somewhere to put bytes, not the algorithm.
Tell every open server about a changePUBLISH, O(N + M) for N subscribers and M patternsNot availablePub/sub is fire-and-forget: a subscriber that is disconnected misses the message. Use Streams when it must not.
A node diesSentinel promotes a replica; writes not yet copied are lostThat node’s share of keys misses and refills from the databaseRedis keeps most data at the cost of running replicas. Memcached accepts a burst of misses at the cost of database load.
Restart for a deployReload the RDB or AOF; the load takes longer as the dataset growsComes back emptyCold-start load on your database is the hidden price of a cache that cannot persist.
Use a 32-core boxOne command thread per instance (I/O threads only parse); run several instances or shardsWorker threads in one process share the hash table, guarded by striped item locksThis is Memcached’s real edge, and it only matters at very high request rates of plain gets.
Store millions of tiny valuesPer-key overhead; group small values into hashes to use the compact encodingSlab allocator: each item takes the smallest chunk class that fits, and the rest of the chunk is wastedBoth waste some memory, in different places. Measure with your real value sizes before trusting either claim about efficiency.
Cache one large objectA string can hold up to 512 MB, but a big value blocks the one thread while it is copied1 MB per item by defaultIf you are near either limit, cache smaller pieces. Large values hurt latency on both.

Read down the Space column and a pattern shows. Memcached’s answer to anything past get, set and count is “do it in the application”, which moves work, round trips and race handling into your code. Redis’s answer is usually one command, paid for with a single thread you must not block and replicas you must run. If your workload lives entirely in the first two rows, the leaner tool is a fair choice. If it touches any row below them, you are choosing where that logic lives. Logic in Redis is one command your whole fleet shares. The same logic in the application is code each service writes, tests and gets wrong on its own.

Your call

Which would you pick?

Three situations. Pick the side you'd actually build — the explanation follows.

You need caching plus sorted sets, counters and pub/sub in the same system.

A colleague enables Redis persistence and says the cache can now be the system of record.

A pure look-aside cache of small opaque strings, multi-threaded, with no need for data structures.

Frequently asked

Quick answers

What is the main difference between Redis and Memcached?

Memcached is a minimal, multithreaded key-value cache for strings only, with no persistence. Redis is a data-structure server: it offers lists, sets, sorted sets, hashes, streams and more, plus persistence, replication and pub/sub. Both cache; Redis does much more.

Is Redis or Memcached faster?

For plain get/set both are extremely fast and memory-bound; differences are usually negligible. Memcached’s multithreading can edge ahead on huge multi-core boxes for simple key-value at very high concurrency, but Redis’s speed is more than enough for nearly all workloads and it does far more.

Does Memcached support persistence?

No. Memcached is purely in-memory — restart it and the cache is empty. Redis offers persistence (RDB snapshots and the AOF log) plus replication and failover, so its data can survive restarts and node failures, not just act as a cache. That does not make it a system of record by default: with AOF's usual once-a-second fsync a crash can lose about a second of writes, and replication is asynchronous, so a failover can drop recent writes.

Which should I use, Redis or Memcached?

Default to Redis unless you have a specific reason not to — it caches like Memcached and adds data structures, persistence and messaging, so it scales with your needs. Choose Memcached when you want a deliberately lean, simple cache for strings and cache loss is harmless.

▶  Watch it explained

Redis vs Memcached: a simple bucket, or a toolbox?

Redis vs Memcached · Engineering · Vibe Engines · 2026
Finished this one? 0 / 209 Handbooks done
NextThe Caching Patterns Handbook Next on the “Data, and where it lives” ladder · rung 9 of 9

Explore the topic

See this alongside everything else on the same subject — handbooks, system designs, challenges and tools, in one place.

More Handbooks