Amazon ElastiCache
- Managed Redis or Memcached
- Caches are in-memory DB with high performance & low latency
- Helps reduce load off of DBs for read-intensive workloads
- Helps application to be stateless
Use Case - DB Cache
- Application queries to ElastiCache
- If not available, get from RDS and store in ElastiCache
- Cache must have an invalidation strategy to ensure only the most current data is used
Use Case - User Session Store
- The user logs into any of the application
- The application writes the session data into ElastiCache
- The user hits another instance of the application
- The instance retrieves the session data to keep userโs login
Redis vs Memcached
- Redis
- Multi-AZ with Auto-Failover
- Read Replicas to scale reads and have HA
- Data durability using AOF persistence
- Backup and restore features
- Supports Sets and Sorted Sets
- Memcached
- Multi-node for partitioning of data (sharding)
- No HA
- Non persistent
- No backup and restore
- Multi-threaded architecture
Patterns for ElastiCache
- Lazy Loading
- All the read data is cached, data can become stale in the cache
- Write Through
- Adds or update data in the cache when written to DB (no stale data)
- Session Store
- Store temporary session data in the cache (using TTL features)
Cache Security
- ElastiCache supports IAM Authentication for Redis
- IAM policies on ElastiCache are only used for AWS API-level security
- Redis Auth
- Can set a password/token when creating Redis cluster
- Extra level of security for cache (on top of SGs)
- Supports SSL in-flight encryption
- Memcached
- Supports SASL-based authentication
ElastiCache Redis OSS 7 Upgrade
ElastiCache ๊ฐ์ Managed Service ๋ EoL ์ด์ ์ ๋ฒ์ ์ ๊ทธ๋ ์ด๋๋ฅผ ํ์ง ์์ผ๋ฉด Premium ์ง์์ ์ํ ์ถ๊ฐ ์๊ธ์ด ๋ฐ์ํ๋ค. ๋๋ฌธ์ 26๋ 1์์ ํ์ค ์ง์์ ์ข ๋ฃํ๋ Redis OSS v5 ๋ 27๋ 1์์ ํ์ค ์ง์์ ์ข ๋ฃํ๋ Redis OSS v6 ๋ฒ์ ์ ์์ง์ ์ฌ์ฉํ๋ ๊ฒฝ์ฐ ๋ฏธ๋ฆฌ Redis OSS v7 ์ผ๋ก ์ ๊ทธ๋ ์ด๋ํด์ฃผ๋ ๊ฒ์ด ์ข๋ค.
๊ณต์๋ฌธ์์ ๋ฐ๋ฅด๋ฉด ๊ธฐ๋ณธ์ ์ผ๋ก ElastiCache Redis ์ ๊ทธ๋ ์ด๋๋ ๋ฐ์ดํฐ ๋ณด์กด๊ณผ ๋ค์ดํ์์ด ๋ฐ์ํ์ง ์๋๋ก ์ค๊ณ๋์ด์๋ค. ํ์ง๋ง ํน์ ๋ชจ๋ฅผ ๋ฐ์ดํฐ ์ ์ค์ ๋ฐฉ์งํ๊ธฐ ์ํด ์ ๊ทธ๋ ์ด๋๊ฐ ์งํ๋๊ธฐ ์ ์ ๋ฐฑ์ Snapshot ์ ๋ ๋๋ ๊ฒ์ด Best Practice ๋ค.
Upgrade
resource "aws_elasticache_replication_group" "example" {
replication_group_id = "example"
description = "example description"
node_type = "cache.t2.micro"
num_cache_clusters = 2
port = 6379
subnet_group_name = aws_elasticache_subnet_group.example.name
security_group_ids = [aws_security_group.example.id]
parameter_group_name = "default.redis7"
engine_version = "7.1"
transit_encryption_enabled = true
auth_token = "abcdefgh1234567890"
auth_token_update_strategy = "ROTATE"
}
ElastiCache ๋ฅผ ์
๊ทธ๋ ์ด๋ํ๊ธฐ ์ํด์ Engine Version ๊ณผ ๋ฒ์ ์ ๋ง๋ Param Group ์ ์ค๋นํด์ผ ํ๋ค. Param Group ์ AWS ์์ ๊ธฐ๋ณธ์ผ๋ก ์ ๊ณตํ๋ default.redis7 default.redis7.cluster.on ๋ฑ์ด ์กด์ฌํ๋ค. .cluster.on ๋ฅ๋ ElastiCache Cluster Mode ๋ฅผ ํ์ฑํํ์ ๋ ์ฌ์ฉํ ์ ์๋ค.
Terraform Apply ์ดํ ์ ๊ทธ๋ ์ด๋๊ฐ ๋ฐ๋ก ์งํ๋์ง ์์ ์ ์๋๋ฐ, ์ด๋ ElastiCache Maintenance Window ๊ฐ ์ ๊ทธ๋ ์ด๋ ๋ฑ ๋ณ๊ฒฝ ๊ฐ๋ฅ ์๊ฐ์ ์ ์ฝํ๊ธฐ ๋๋ฌธ์ด๋ค. ํด๋น ํด๋ฌ์คํฐ๋ฅผ ์ฌ์ฉํ๋ ํด๋ผ์ด์ธํธ์ ์ฌ์ฉํจํด์ ๋ฐ๋ผ Maintenance Window ๊ฐ ์์ดํ ์ ์๋ค. Maintenance Window ๊ฐ ์์๋๋ฉด Redis 7 ์ ํธ์คํ ํ๋ ์๋ก์ด ๋ ธ๋๋ค์ด ์์ฐจ์ ์ผ๋ก ํด๋ฌ์คํฐ์ ์กฐ์ธํ๋ค.
Verification
| ๋ฉํธ๋ฆญ | ์ค๋ช | ๋ฐ์ดํฐ ์ ์ค ์ฌ๋ถ ํ๋จ ํฌ์ธํธ |
|---|---|---|
aws.elasticache.curr_items | Redis ๋ด ์ ์ฒด ํค ๊ฐ์ | ์ ๊ทธ๋ ์ด๋ ์ ํ ๊ฐ์ด ๋น์ทํ๋ฉด ๋ฐ์ดํฐ ๋ณด์กด๋จ. |
aws.elasticache.evictions | ๋ฉ๋ชจ๋ฆฌ ๋ถ์กฑ์ผ๋ก ๊ฐ์ ์ญ์ ๋ ํค ์ | ์ ๊ทธ๋ ์ด๋ ์งํ spike๊ฐ ์์ผ๋ฉด ์ผ๋ถ ๋ฐ์ดํฐ ๋ ์๊ฐ์ ๊ฐ๋ฅ์ฑ ์์. |
aws.elasticache.cache_hits / aws.elasticache.cache_misses | ์บ์ ์กฐํ ์ฑ๊ณต/์คํจ ํ์ | ์
๊ทธ๋ ์ด๋ ์งํ miss๊ฐ ๊ธ์ฆํ๋ฉด ๋ฐ์ดํฐ flush ์์ฌ ๊ฐ๋ฅ. |
aws.elasticache.bytes_used_for_cache | ์บ์์ ์ค์ ์ ์ฅ๋ ๋ฐ์ดํฐ ํฌ๊ธฐ(byte) | ์ ๊ทธ๋ ์ด๋ ํ ๊ฐ์๊ธฐ ์ค๋ฉด ์บ์๊ฐ ๋น์์ก์ ๊ฐ๋ฅ์ฑ ๋์. |
aws.elasticache.new_connections | ์๋ก ์์ฑ๋ Redis ํด๋ผ์ด์ธํธ ์ฐ๊ฒฐ ์ | ์ ๊ทธ๋ ์ด๋ ํ spike ์์ผ๋ฉด ์ฌ์ฐ๊ฒฐ ๋ฐ์ ๊ฐ๋ฅ (์ ์์ ์ธ failover). |
aws.elasticache.replication_bytes | ๋ณต์ ๋ณธ๊ณผ์ ๋๊ธฐํ๋ ๋ฐ์ดํฐ ์ | ์ ๊ทธ๋ ์ด๋ ์ replication ์ด ์ฌ์์๋๋ฉด ์ฆ๊ฐ ๊ฐ๋ฅ (์ ์ ๋ฒ์). |
| Datadog Resources ๋ฅผ ํ์ฉํ์ฌ ElastiCache Redis ์ ๋ฉํธ๋ฆญ์ ํ์ธํ ์ ์๋ค. ์ด๋ฅผ ํตํด ์ ๊ทธ๋ ์ด๋ ์ค ๋ฐ์ดํฐ ์ ์ค์ด ๋ฐ์ํ๋์ง ํ์ธํ ์ ์๋ค. Datadog ์ฐ๋ ์ ์ ๋ฉํธ๋ฆญ ์ธ์๋ ๋ ๋ค์ํ ๋ฉํธ๋ฆญ์ ์ง์ํ๋ค. ์์ธํ ๋ด์ฉ์ ๊ณต์๋ฌธ์๋ฅผ ์ฐธ์กฐํ์. |
Maintenance Window ๊ฐ ์์๋๋ฉด Upgrade ๊ฐ ์งํ๋๊ณ aws.elasticache.new_connections ๊ณผ aws.elasticache.replication_bytes ๋ฑ์ Spike ๊ฐ ๊ฐ์ง๋๋ค. Redis7 ์ ํธ์คํ
ํ๋ ์๋ก์ด ๋
ธ๋๊ฐ ํด๋ฌ์คํฐ์ ์กฐ์ธํ๊ณ ๊ธฐ์กด ํด๋ผ์ด์ธํธ๋ค์ด ์ฌ์ฐ๊ฒฐํ๋ ๊ณผ์ ์์ ๊ด์ธก๋๋ ์งํ๋ค.