Comparison

Memcached vs Redis for Application Caching

Choose Memcached for disposable key-value caching or Redis for application-side data structures. Replay cache misses, evictions, and cold starts before switching.

Editorial update

Decision in brief

Choose Memcached when the application only needs to get and replace opaque values by key and can rebuild them cheaply. Choose Redis when hashes, sorted sets or atomic operations on structured data simplify a measured application workload. Keep business-critical state and a disposable cache in separate instances if they need different eviction or recovery settings.

Choose your cache: Memcached — Replace values. Redis — Work with structures. Separate state — Set eviction rules.
Replay a cache trace and compare tail latency and the load sent to the origin.

See discussion trends ↓

Choose by what a key means and what can be lost

A Memcached item holds application-serialized bytes with a key and expiration. Memcached supports compare-and-swap for a whole value, so it can handle conditional replacement when racing writers matter. Check the client’s TTL handling before migration. Memcached interprets expirations beyond 30 days as absolute Unix timestamps.

Redis offers data structures with server-side operations and optional RDB snapshots and AOF logging. A restarted cache can repopulate from the application’s source of truth. Retained state needs its own memory settings, persistence policy and restore test. A Redis logical database number alone does not isolate memory pressure or persistence. When you set maxmemory, allow additional host memory for overhead and any configured replication or persistence buffers.

RequirementStarting choiceWhat decides
Serialized fetch-by-key valuesMemcached or the cache you already operateApplication p99, origin fallback and operator effort under the same cache budget
Atomic changes to individual fields or ranking by scoreRedis hashes or sorted setsCorrectness at expiry boundaries and memory per useful key
Recovery after restart for application stateA separately operated Redis deployment, or the primary databaseObserved loss window, recovery time and application behavior while state is unavailable
Traffic still fits the primary storeNo network cache yetA trace shows enough repeated expensive work to justify an added dependency

What two HN threads show about running a cache

In a comparison thread, jitl said Notion used Redis for other workloads and Memcached for caching. That example supports choosing by responsibility. Their speed claim reflects that workload, so compare end-to-end latency under your own payload sizes, network and key skew.

In a separate Show HN, sr-white introduced Memtui after finding Memcached inspection and value formats awkward to debug. Before changing engines, practice distinguishing an expired or evicted entry from a serialization error or a failed connection.

Replay an application cache trace before switching

Use synthetic or sanitized keys from representative payload distributions. Agree on tail latency, maximum origin queries per second and the recovery window before running tests.

  1. Pin a deployment and client version for each cache. Match host resources, network placement, TTL and payloads. Run an origin-only baseline, then warm each cache with the same request trace.
  2. Replay normal and burst traffic with representative key skew and expired keys. Compare application p95 and p99 latency, hit rate, cache resident memory and origin load.
  3. Restart the cache and impose memory pressure in staging. Verify bounded retries, request coalescing or other miss protection, and recovery of an empty cache without breaching the origin budget.
  4. Adopt the simpler candidate that passes both normal and degraded thresholds. Stop if cold-start traffic overwhelms the origin or if loss of supposed cache entries changes business outcomes.

Related articles