Amazon ElastiCache là dịch vụ managed in-memory caching, hỗ trợ Redis và Memcached, giúp giảm latency database và tăng throughput ứng dụng.
ElastiCache for Redis hỗ trợ data structures phong phú (strings, hashes, lists, sets, sorted sets, streams), persistence (RDB/AOF snapshots), replication (primary + read replicas), cluster mode (sharding tự động), pub/sub, Lua scripting, transaction; phù hợp cho session store, leaderboard, pub/sub, distributed locking, job queue. ElastiCache for Memcached đơn giản hơn, chỉ key-value string, multi-threaded (tận dụng multi-core tốt hơn), không có persistence hay replication, dễ horizontal scale; phù hợp khi chỉ cần simple object caching và horizontal scaling thuần túy.
Caching patterns:
- Cache-aside (lazy loading) — app check cache trước, miss thì query DB rồi populate cache
- Write-through — ghi vào cache và DB đồng thời, data luôn fresh nhưng write latency cao
- Write-behind (write-back) — ghi vào cache trước, async sync xuống DB, giảm write latency nhưng risk data loss
- Read-through — cache layer tự handle DB read khi miss
TTL đặt phù hợp tránh stale data; Cache Stampede problem giải quyết bằng mutex/probabilistic early expiration. ElastiCache Serverless (2023) tự scale capacity tự động.
Amazon ElastiCache is a managed in-memory caching service that supports Redis and Memcached, helping reduce database latency and increase application throughput.
ElastiCache for Redis supports rich data structures (strings, hashes, lists, sets, sorted sets, streams), persistence (RDB/AOF snapshots), replication (primary + read replicas), cluster mode (automatic sharding), pub/sub, Lua scripting, and transactions — suitable for session stores, leaderboards, pub/sub, distributed locking, and job queues. ElastiCache for Memcached is simpler, supports only key-value strings, is multi-threaded (better multi-core utilization), has no persistence or replication, and scales horizontally easily — suitable when you only need simple object caching and pure horizontal scaling.
Caching patterns:
- Cache-aside (lazy loading) — the app checks the cache first, queries the DB on a miss, then populates the cache
- Write-through — writes to both cache and DB simultaneously, keeping data fresh but increasing write latency
- Write-behind (write-back) — writes to cache first, async syncs to DB, reducing write latency but risking data loss
- Read-through — the cache layer handles DB reads on a miss automatically
Set appropriate TTLs to avoid stale data; solve the Cache Stampede problem with mutex or probabilistic early expiration. ElastiCache Serverless (2023) auto-scales capacity automatically.