Valkey vs Redis vs Memcached
While Redis and Memcached have been long-standing competitors, Valkey is a new, community-driven open-source fork of Redis, created in response to changes in Redis's licensing.
TL;DR
| Feature | Memcached | Redis | Valkey |
|---|---|---|---|
| Primary Goal | Simple, fast caching | Multi-purpose data structure server | Community-driven evolution of Redis |
| Data Model | Simple Key-Value (strings) | Advanced Data Structures | Advanced Data Structures (same as Redis) |
| Persistence | None (in-memory only) | RDB snapshots and AOF logs | RDB snapshots and AOF logs |
| Replication | None built-in (third-party) | Primary-Replica | Primary-Replica |
| Clustering | None built-in (client-side) | Redis Cluster | Redis Cluster (initially) |
| Extensibility | Limited | Lua scripting, Modules | Lua scripting, Modules |
| Threading Model | Multi-threaded | Single-threaded (event loop) | Multi-threaded (initially) |
| License | BSD | Source-Available (SSPL/RSAL) | BSD (Community Governed) |
Detailed Comparison
1. Core Philosophy and Origins
- Memcached: The original high-performance, distributed memory caching system. Its design philosophy is simplicity and speed. It does one thing and does it exceptionally well: serve as a transient cache for simple string data.
- Redis: Started as a more powerful alternative to Memcached. Its philosophy is to be a versatile, multi-purpose "data structure server." It's not just a cache but can act as a database, message broker, and more, thanks to its rich feature set.
- Valkey: A direct response to Redis Inc. changing the license of the Redis core repository from the open-source BSD to the source-available SSPL and RSAL. Valkey is a community-governed, open-source fork of Redis. Its goal is to continue the development of Redis under the open-source BSD license, ensuring it remains free to use, modify, and distribute without the restrictions of the new licenses. It is backed by major tech companies like AWS, Google Cloud, and Oracle.
2. Data Structures
This is a major point of differentiation.
- Memcached: Simple key-value store. The values are treated as opaque strings. You can
set,get, anddeletekeys. - Redis: Supports a rich set of advanced data structures in memory. This allows for more complex operations to be offloaded from the application to the data store. Key data types include:
- Strings: Similar to Memcached.
- Lists: Ordered sequences of strings.
- Sets: Unordered collections of unique strings.
- Hashes: Maps of field-value pairs.
- Sorted Sets: Sets where each member has a score, allowing for ranking and ordering.
- Bitmaps & HyperLogLogs: For space-efficient, large-scale analytics.
- Streams: An append-only log for event-driven architectures.
- Valkey: As a fork of Redis, it inherits all of Redis's advanced data structures. Its development path will likely see these structures evolve and new ones added over time.
3. Persistence
- Memcached: No persistence. It is a pure in-memory cache. If a server restarts or crashes, all the data it held is lost.
- Redis & Valkey: Both offer robust persistence options, making them suitable for use as a primary database:
- RDB (Snapshotting): Creates point-in-time snapshots of the dataset at specified intervals.
- AOF (Append-Only File): Logs every write operation. This provides better durability than RDB.
4. Scalability and High Availability
- Memcached: Client-side clustering. It does not have built-in replication or clustering. To scale out, you must implement sharding logic in your application client, which distributes keys across multiple Memcached instances.
- Redis & Valkey: Provide built-in solutions for scalability and high availability:
- Primary-Replica Replication: A primary instance can have one or more replicas that contain a copy of the data, allowing for read scaling and failover.
- Clustering: Redis Cluster provides automatic sharding, allowing you to scale writes and dataset size horizontally across multiple nodes. Valkey inherits this functionality.
5. Multi-Threading
- Memcached: Multi-threaded. It can utilize multiple CPU cores to handle many concurrent connections, which can be advantageous for high-throughput caching workloads.
- Redis: Primarily single-threaded, using an event loop model. This simplifies the data model and avoids race conditions, but it can be a bottleneck on multi-core machines. Newer versions of Redis have introduced I/O threading to offload network operations to other threads.
- Valkey: Has announced plans to introduce a more threaded model to improve performance on modern hardware, which could become a key differentiator from Redis in the future.
Which One Should You Use?
- Choose Memcached if:
- You need a simple, high-throughput, transient cache.
- Your data is unstructured string data.
- You are comfortable with implementing scaling logic on the client side.
- You do not need any persistence or advanced features.
- Choose Redis if:
- You need advanced data structures and atomic operations on them.
- You require data persistence for durability.
- You need built-in replication and clustering for high availability and scalability.
- You are building more than just a cache (e.g., a real-time leaderboard, message queue, or session store).
- Your project's licensing is compatible with the SSPL or RSAL.
- Choose Valkey if:
- You want the power and features of Redis but need to use a permissive, open-source license (BSD).
- You want to be part of a community-driven project backed by major industry players.
- You are starting a new project and want to avoid any future licensing complexities associated with Redis.
- You are interested in its future development direction, particularly around improved multi-threading.
Recommended Reading
SponsoredVersus
- 32-bit vs 64-bit
- AES vs RSA
- Agent vs Agentless
- Annotations vs Decorators
- Terraform vs Ansible
- BASH vs ZSH
- BigQuery vs Bigtable
- Block Storage vs File Storage vs Object Storage
- Canvas vs SVG
- cgroupfs vs systemd
- Constructor vs Init() vs Factory
- Container Image vs Helm Chart vs OCI Bundle
- Containers vs Virtual Machines (VMs)
- C vs C++
- Java vs C++
- Rust vs C++
- crictl vs ctr
- Dagger vs Guice
- DMA vs RDMA
- DOM vs Virtual DOM vs Shadow DOM
- DQL vs DDL vs DCL vs DML
- eBPF vs Sidecar
- Flux vs Redux
- Full Disk Encryption vs Partition Encryption
- Gatekeeper vs OPA
- Google vs Open Source
- Why MCP uses JSON-RPC 2.0 instead of grpc
- gRPC vs OpenAPI
- gtag.js vs Google Tag Manager (GTM)
- Versus
- Kotlin vs Java
- Jetty vs Netty
- .js vs .jsx vs .ts vs .tsx
- Kata Containers vs KubeVirt
- Linux Namespace vs Kubernetes Namespace
- Linux vs BSD
- LLVM vs JVM
- Data Mining vs Machine Learning vs Artificial Intelligence vs Data Science
- Managed Kubernetes vs Self-managed Kubernetes
- Management Plane vs Control Plane vs Data Plane
- Microcontroller vs Microprocessor vs Computer
- MMU vs IOMMU
- Single-tenant vs Multi-tenant vs Multi-single-tenant
- Multithreading vs Multiprocessing vs Distributed Systems
- Node.js vs Erlang
- OCI Image vs Docker Image
- OCI vs CRI
- OpenSSH vs OpenSSL
- Pass-by-value vs Pass-by-reference
- Podman vs nerdctl
- POSIX vs SUS vs LSB
- Private Key vs Public Key vs Certificate
- Proto Edition 2024 vs Proto Edition 2023
- Proto2 vs Proto3 vs Proto Editions
- Message Queue vs PubSub
- React vs Flutter vs Angular
- REST vs SOAP
- RSA vs ECDSA
- select vs. poll vs. epoll
- SLI vs SLO vs SLA
- Spanner vs Bigtable
- Static Site Generation vs Server-side Rendering vs Client-side Rendering
- Stack based VM vs Register based VM
- Stateless vs Stateful
- Strong Consistency vs Eventual Consistency
- stubs vs mocks vs fakes
- Subroutines vs Coroutines vs Generators
- Software Engineer vs Site Reliability Engineer
- Symlinks vs Hard Links
- JAX vs Tensorflow
- Tensorflow vs PyTorch
- Terminal vs Shell
- Throttling vs Load Shedding
- Unix Domain Sockets vs Network Sockets
- Unix Domain Sockets vs Shared Memory
- URI vs URN vs URL vs URC
- Valkey vs Redis vs Memcached
- Vi vs Vim vs gVim vs Neovim
- WAL vs rollback journal

