EIVUS

Redis and Memcached for Hosted Apps

In-memory caches on your server: when to use each and how to size.

Back to blog

Redis is feature-rich (data structures, persistence, pub/sub); Memcached is simple and multi-threaded. Both reduce DB load. Run on the same host for low latency or dedicate a small instance. Set memory limits and eviction policies.

Redis vs Memcached

  • Redis: Data structures (strings, hashes, lists, sets), optional persistence, pub/sub, Lua scripting. Single-threaded (per core). Good when you need more than key-value or persistence.
  • Memcached: Simple key-value; multi-threaded; no persistence. Often faster for pure cache at high concurrency. Lower memory overhead per key.

Sizing and placement

  • Same host: Run Redis/Memcached on the app server for lowest latency. Share RAM with the app; set a memory limit so cache does not starve the app.
  • Dedicated instance: Small VPS or container just for cache when you have many app servers or need more memory. Slight network latency but shared across app tier.
  • Memory: Allocate enough for your working set (hot keys). Set maxmemory and eviction policy (e.g. allkeys-lru) so the server does not OOM.

Best practices

  • Eviction: Configure eviction policy (LRU, LFU, etc.) so when memory is full the server evicts keys instead of failing.
  • Persistence (Redis): RDB and/or AOF if you need durability. For pure cache, persistence can be disabled for simplicity and performance.
  • Security: Bind to localhost or private IP; use a password if the cache is on a shared network. Restrict access with firewall.

Summary

Redis = rich features and optional persistence; Memcached = simple, multi-threaded cache. Size memory for working set; set eviction; run same-host for latency or dedicated for scale.

Clients who trust us