What is the difference between ElastiCache for Redis and ElastiCache for Memcached?
Memcached is a simple, multi-threaded key-value cache for plain caching. Redis supports richer data types, persistence, replication with failover, and features like pub/sub, so it suits caching plus sessions, leaderboards and queues.
Explain it simply
Memcached is a plain notice board: you pin a paper with a label and read it later, and if the board is cleared it is gone. Redis is a smart board with lists, counters and sorted rankings built in, and it can keep a backup copy and have a stand-by board ready.
Example
Redis Memcached
Data types : strings, lists, sets, strings only
sorted sets, hashes
Persistence : snapshots / append file none
Replication : replicas, Multi-AZ, none
automatic failover
Threading : mostly single-threaded multi-threaded
Scaling : cluster mode (sharding) add nodes, client-side sharding
Extras : pub/sub, Lua, geospatial very simple
Typical use : session store, leaderboard, simple, large, throwaway
rate limiter, cache object cacheExample: a cricket app can keep a live leaderboard of top scorers in a Redis sorted set, which updates and ranks in one command. That is not possible with Memcached.
Both sit in front of a database to cut read load and latency. If you are unsure, Redis is usually the safer pick.
What to say in the interview
"Memcached is a simple multi-threaded cache. Redis adds data structures, persistence, replication and failover, so it also works for sessions, leaderboards and rate limiting. Unless I just need a very simple cache, I choose Redis."
Common mistakes
- Storing the only copy of important data in a cache.