Redis vs Memcached: Clarifications and Comparative Analysis
This article critically examines common claims that Memcached is superior for caching by comparing its design, threading, disk I/O, memory efficiency, LRU behavior, smart caching features, persistence, replication, observability, and Lua scripting capabilities against Redis, concluding that the two systems have distinct trade‑offs depending on use case.
The author, referencing a blog post by Mike Perham (author of Sidekiq), challenges the assertion that Memcached is a better cache than Redis, arguing that both systems have merits and that the choice should be based on accurate technical knowledge.
Memcached is designed for caching : The author dismisses this as a non‑argument, noting that Redis can also serve as a cache.
It has no disk I/O : Redis can be configured to operate purely in memory, and persistence can be disabled or performed only on shutdown using the SHUTDOWN SAVE command, making disk I/O optional.
It is multithreaded : While Memcached is multithreaded, Redis can achieve comparable throughput using pipelining; a single Redis instance can handle hundreds of thousands of operations per second, and multiple Redis processes can be run to scale horizontally.
The author also notes that operation quality matters: simple GET/SET commands in Redis have similar cost to Memcached, but complex commands or Lua scripts can reduce round‑trips and improve efficiency.
True Differences
Memory efficiency : Memcached historically uses a slab allocator that can cause fragmentation, whereas Redis employs compact encodings (e.g., integer sets) and data structures that often use memory more efficiently for certain workloads.
Redis LRU vs. slab allocator : Redis’s recent LRU implementation approximates true LRU behavior, while Memcached’s LRU is tied to its slab allocation, which can lead to less accurate eviction.
Smart caching : Redis offers advanced data types such as sorted sets, lists, and hashes, enabling patterns like capped lists, popularity ranking, and more sophisticated cache invalidation that Memcached cannot natively provide.
Persistence and replication : Redis provides optional snapshotting, AOF persistence, and built‑in replication, which can be valuable for high‑availability cache scenarios; these features are absent in pure Memcached deployments.
Observability : Redis exposes extensive runtime metrics, and commands such as CLIENT LIST and MONITOR allow deep inspection of client activity and performance.
Lua scripting : Redis’s embedded Lua engine enables atomic, server‑side processing (e.g., extracting a field from a JSON‑like hash) that can dramatically reduce network overhead.
Conclusion
Memcached remains a powerful, simple caching solution, but Redis offers a richer feature set and comparable performance for many workloads. The author encourages readers to evaluate both systems against their specific requirements and to update the article if any statements prove inaccurate.
Architect
Professional architect sharing high‑quality architecture insights. Topics include high‑availability, high‑performance, high‑stability architectures, big data, machine learning, Java, system and distributed architecture, AI, and practical large‑scale architecture case studies. Open to ideas‑driven architects who enjoy sharing and learning.
How this landed with the community
Was this worth your time?
0 Comments
Thoughtful readers leave field notes, pushback, and hard-won operational detail here.