Skip to content

Commit

Permalink
feat: [AWS] AWS ElastiCache๋ž€?? (#41)
Browse files Browse the repository at this point in the history
  • Loading branch information
joojae02 authored Jan 22, 2025
1 parent fb71f94 commit 18ee0ab
Showing 1 changed file with 107 additions and 0 deletions.
107 changes: 107 additions & 0 deletions AWS/ElastiCache.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,107 @@

## AWS ElastiCache๋ž€??

![](https://i.imgur.com/DwAkz37.png)

ElastiCache๋Š” ์ธ๋ฉ”๋ชจ๋ฆฌ ์บ์‹ฑ ์„œ๋น„์Šค์ด๋‹ค.
์‚ฌ์‹ค Redis๋ผ๊ณ  ์ดํ•ดํ•ด๋„ ๋ฌด๋ฐฉํ•˜๋‹ค.

Memcached, Redis, Valkey ๋“ฑ์ด ์žˆ๊ธดํ•˜์ง€๋งŒ
๋ณดํ†ต Redis๋งŒ ์‚ฌ์šฉํ•œ๋‹ค.
~~์š”์ฆ˜์€ Valkey๋„..~~

### ์ธ๋ฉ”๋ชจ๋ฆฌ ์บ์‹œ๋ž€?

๋ณดํŽธ์ ์œผ๋กœ ์‚ฌ์šฉํ•˜๋Š” RDBMS์™€ ๊ฐ™์€ ๋ฐ์ดํ„ฐ๋ฒ ์ด์Šค๊ฐ€ ์•„๋‹Œ
๋ชจ๋“  ๋ฐ์ดํ„ฐ๋ฅผ ๋ฉ”๋ชจ๋ฆฌ(RAM)์— ์˜ฌ๋ ค๋†“๊ณ  ์‚ฌ์šฉํ•˜๋Š” ๋ฐ์ดํ„ฐ๋ฒ ์ด์Šค์˜ ์ผ์ข…์ด๋‹ค.

๋ณดํ†ต RDBMS๋Š” ๋””์Šคํฌ์— ๋ฐ์ดํ„ฐ๋ฅผ ์˜๊ตฌ์ ์œผ๋กœ ์ €์žฅํ•˜๊ณ  ํ•„์š”ํ•œ ๋ฐ์ดํ„ฐ๋ฅผ ๋ฉ”๋ชจ๋ฆฌ์— ์˜ฌ๋ ค ์‚ฌ์šฉํ•˜๋Š” ๊ตฌ์กฐ์ด๋‹ค.

์ธ๋ฉ”๋ชจ๋ฆฌ๋Š” ๋””์Šคํฌ์— ์ ‘๊ทผํ•˜์ง€ ์•Š๊ณ  ๋ฉ”๋ชจ๋ฆฌ๋กœ๋งŒ ์ฒ˜๋ฆฌ๋ฅผ ํ•˜๊ธฐ์— ๋ฐ์ดํ„ฐ ์ €์žฅ, ๊ฒ€์ƒ‰ ์†๋„๊ฐ€ ๋งค์šฐ. ๋งค์šฐ ๋น ๋ฅด๋‹ค.
๋‹ค๋งŒ ๋ฉ”๋ชจ๋ฆฌ ์šฉ๋Ÿ‰์ด ์ž‘์€ ๋งŒํผ ๋น„์šฉ์ด ๋น„์‹ธ๊ณ  ์„œ๋ฒ„๊ฐ€ ๊บผ์ง€๊ฒŒ ๋˜๋ฉด ๋ฐ์ดํ„ฐ๋Š” ์†Œ๋ฉธ๋œ๋‹ค.

ํ˜„์žฌ ElastiCache์—์„œ ์ง€์›ํ•˜๋Š” ์ข…๋ฅ˜๋Š”
- Redis
- Memcached
- Valkey
3๊ฐ€์ง€์ด๋‹ค.

Valkey๋Š” Redis๊ฐ€ ๋ผ์ด์„ ์Šค ์ •์ฑ…์„ ๋ณ€๊ฒฝ ํ›„ AWS์™€ ๊ฐ™์€ Provider๋“ค์ด Redis ์‚ฌ์šฉํ•˜๋Š”๊ฒƒ์— ์ œ์•ฝ์ด ์ƒ๊ธธ ์ˆ˜ ์žˆ๊ฒŒ ๋˜๋ฉด์„œ ์ด์— ๋ฐ˜๋ฐœํ•˜๋ฉฐ ๋งŒ๋“ค์–ด์ง„ Redis Fork ํ”„๋กœ์ ํŠธ์ด๋‹ค.

๋ฌผ๋ก  ์šฐ๋ฆฌ ๊ฐ™์€ ๊ฐœ๋ฐœ์ž๋“ค์ด Redis ์„ค์น˜ํ•ด์„œ ์‚ฌ์šฉํ•˜๊ณ  ๋ผ์ด๋ธŒ๋Ÿฌ๋ฆฌ ์‚ฌ์šฉํ•˜๋Š”๊ฑด ๋ฌธ์ œ๊ฐ€ ์—†๋‹ค!

### ํŠน์ง•

์ธ๋ฉ”๋ชจ๋ฆฌ ์บ์‹ฑ ์„œ๋น„์Šค์ธ๋งŒํผ
IO๊ฐ€ ๋งŽ์€ ์„œ๋น„์Šค์—์„œ ์ž‘์—… ๋ถ€ํ•˜๋ฅผ ์ค„์ด๊ธฐ ์œ„ํ•ด์„œ ์‚ฌ์šฉํ•œ๋‹ค.
- ์˜ˆ) ์†Œ์…œ ๋„คํŠธ์›Œํ‚น, ๋ฏธ๋””์–ด ๊ณต์œ , ๊ฒŒ์ž„, ๋“ฑ๋“ฑ

๋ณดํ†ต ์„œ๋น„์Šค์—์„  ์‘๋‹ต ์†๋„๋ฅผ ์ค„์ด๊ธฐ ์œ„ํ•ด์„œ ์บ์‹ฑ์šฉ์œผ๋กœ ๋งŽ์ด ์‚ฌ์šฉํ•œ๋‹ค.
๋˜ํ•œ Redis๋Š” ๋‹ค์–‘ํ•œ ๋ฐ์ดํ„ฐ ๊ตฌ์กฐ๋ฅผ ์ง€์›ํ•˜๊ธฐ์— ์ฝ”์ŠคํŠธ ํšจ์œจ์ด ๋†’์€ํŽธ์ด๋‹ค.

๊ทธ๋ฆฌ๊ณ  ElastiCache๋Š” ๋‹ค์ค‘ AZ, ์„œ๋ฒ„๋ฆฌ์Šค ๊ตฌ์„ฑ์„ ์ง€์›ํ•ด ๋†’์€ ์ˆ˜์ค€์˜ ๊ฐ€์šฉ์„ฑ์„ ๋ณด์žฅํ•œ๋‹ค.

### Memcached vs Redis

๊ฐ ์—”์ง„์€ ๋˜‘๊ฐ™์ด ์ธ๋ฉ”๋ชจ๋ฆฌ ํ‚ค ๋ฒจ๋ฅ˜ ์ €์žฅ์†Œ์ด๋‹ค.
๊ทธ์น˜๋งŒ ์„œ๋กœ ์œ ์ฆˆ์ผ€์ด์Šค๊ฐ€ ์กฐ๊ธˆ ๋‹ค๋ฅด๋‹ค.

์šฐ์„  Memcached๋ฅผ ์„ ํƒํ•˜๋Š”๊ฒŒ ์œ ๋ฆฌํ•œ ์ƒํ™ฉ์œผ๋กœ
- ๊ฐ€๋Šฅํ•œ ๋‹จ์ˆœํ•œ ๋ชจ๋ธ์ด ํ•„์š”ํ•œ ๊ฒฝ์šฐ
- ์—ฌ๋Ÿฌ ์ฝ”์–ด, ์Šค๋ ˆ๋“œ ์žˆ๋Š” ํฐ ๋…ธ๋“œ๋ฅผ ์‹คํ–‰ํ•ด์•ผํ•˜๋Š” ๊ฒฝ์šฐ
- ๋…ธ๋“œ๋ฅผ ์Šค์ผ€์ผ๋งํ•˜๋Š” ๊ธฐ๋Šฅ์ด ํ•„์š”ํ• ๋–„
- ๊ฐ์ฒด๋ฅผ ์บ์‹œ์— ์ €์žฅํ•ด์•ผํ• ๋•Œ

์ด๋ ‡๊ฒŒ ๋ณด๋ฉด Redis ์จ๋„ ๊ดœ์ฐฎ์ง€ ์•Š๋‚˜??๋ผ๋Š” ์ƒ๊ฐ์ด ๋“ค๊ฒƒ์ด๋‹ค.
์‚ฌ์‹ค Redis ์จ๋„ ๋œ๋‹ค.

๊ฐ€์žฅ ํฐ ์ฐจ์ด์ ์€ ์Šค๋ ˆ๋“œ ๋ชจ๋ธ, ์ž๋ฃŒ๊ตฌ์กฐ ์ฐจ์ด๋‹ค.
- Redis๋Š” ์‹ฑ๊ธ€ ์Šค๋ ˆ๋“œ ๊ธฐ๋ฐ˜์ด๋‹ค.
- Memcached ๋Š” ๋ฉ€ํ‹ฐ ์Šค๋ ˆ๋“œ๋ฅผ ์ง€์›ํ•œ๋‹ค.

- Redis ๋‹ค์–‘ํ•œ ์ž๋ฃŒ๊ตฌ์กฐ
- Memcached ๋ฌธ์ž์—ด ํ˜•ํƒœ


๋˜ํ•œ ์‹ฑ๊ธ€ ์Šค๋ ˆ๋“œ๋กœ ๋ฐ์ดํ„ฐ๋ฅผ Atomic ํ•˜๊ฒŒ ๊ด€๋ฆฌํ•œ๋‹ค๋Š” ์žฅ์ ๋„ ์กด์žฌํ•˜๊ณ .
Redis์— ThreadedIO, ํด๋Ÿฌ์Šคํ„ฐ ๋ชจ๋“œ๊ฐ€ ์ถ”๊ฐ€๋˜๋ฉด์„œ
๊ธฐ์กด Memcahced์˜ ์žฅ์ ๋“ค์„ ๋Œ€๋ถ€๋ถ„ ์ปค๋ฒ„ํ•œ๋‹ค.

๊ทธ๋ž˜์„œ ๋Œ€๋ถ€๋ถ„ Redis๋ฅผ ์‚ฌ์šฉํ•œ๋‹ค.

### ๋…ธ๋“œ, ์ƒค๋“œ, ํด๋Ÿฌ์Šคํ„ฐ

![](https://i.imgur.com/97JIQvA.png)

![](https://i.imgur.com/9qegCdV.png)

ElastiCache์—์„œ ์•Œ์•„์•ผํ•  ๊ตฌ์„ฑ ์š”์†Œ๋“ค์ด๋‹ค.

์šฐ์„  Node๋Š” ElastiCache๋ฅผ ์‚ฌ์šฉํ• ๋•Œ ์ตœ์†Œ ๊ตฌ์„ฑ ์š”์†Œ์ด๋‹ค.
- ์˜ˆ) Redis ๋…ธ๋“œ 1๋Œ€

์ƒค๋“œ๋Š” ๋…ธ๋“œ์˜ ๊ทธ๋ฃน์ด๋‹ค.
Master ๋…ธ๋“œ ์™€ 0๊ฐœ ์ด์ƒ์˜ Read Replica๋กœ ๊ตฌ์„ฑ๋˜๊ณ 

ํด๋Ÿฌ์Šคํ„ฐ๋Š” ์ƒค๋“œ์˜ ๊ทธ๋ฃน์ด๋‹ค.


### ์‚ฌ์šฉ ์˜ˆ์‹œ

- ์บ์‹ฑ
- ๋น ๋ฅธ ๋ฐ์ดํ„ฐ ์—‘์„ธ์Šค๋ฅผ ์œ„ํ•ด์„œ ์‚ฌ์šฉํ•œ๋‹ค.
- ๊ฐ™์€ ๋ฐ์ดํ„ฐ์— ๋ฐ˜๋ณต์ ์œผ๋กœ ์ ‘๊ทผํ•˜๋Š” ๊ฒฝ์šฐ ๋ฐ์ดํ„ฐ๋ฅผ ์บ์‹ฑํ•œ๋‹ค.
- API ์‘๋‹ต ์บ์‹ฑ
- ์›น ํŽ˜์ด์ง€ ์บ์‹ฑ
- ์„ธ์…˜ ์Šคํ† ๋ฆฌ์ง€
- `GET`, `SET`, `EXPIRE` ๋“ฑ ๊ฐ„๋‹จํ•œ ๋ช…๋ น์–ด๋ฅผ ํ†ตํ•ด ๊ตฌํ˜„ ๊ฐ€๋Šฅํ•˜๋‹ค.
- ์‹ค์‹œ๊ฐ„ ์ˆœ์œ„
- ์‹ค์‹œ๊ฐ„ ๋ฐ์ดํ„ฐ ์ฒ˜๋ฆฌ๊ฐ€ ๊ฐ€๋Šฅํ•ด ๋žญํ‚น ์‹œ์Šคํ…œ ๋“ฑ์— ์‚ฌ์šฉํ•œ๋‹ค.
- ํŠน์ • ์ ์ˆ˜ ๊ธฐ๋ฐ˜ ๋ฆฌ๋” ๋ณด๋“œ, ์ธ๊ธฐ ๊ฒŒ์‹œ๋ฌผ ๋“ฑ
- `ZSET` ๊ฐ™์€ Sorted Set ๋“ฑ ์ž๋ฃŒ ๊ตฌ์กฐ๋ฅผ ์‚ฌ์šฉํ•˜์—ฌ ๊ตฌํ˜„ํ•œ๋‹ค.
- Message Queue
- ![](https://i.imgur.com/CZd9kre.png)

- Redis๋ฅผ MQ์ฒ˜๋Ÿผ ์‚ฌ์šฉ์ด ๊ฐ€๋Šฅํ•˜๋‹ค.
- Pub/Sub, List, Stream ํ˜•ํƒœ๋กœ ๊ฐ๊ฐ ๊ตฌํ˜„์ด ๊ฐ€๋Šฅํ•œ๋ฐ Kafka ์™€ ๊ฐ™์€ ์ด๋ฒคํŠธ ๋ธŒ๋กœ์ปค์— ๋น„ํ•ด์„œ๋Š” ์•ˆ์ •์„ฑ์ด๋‚˜ ์„ฑ๋Šฅ์ด ๋–จ์–ด์ง€๊ธดํ•œ๋‹ค.
- ์ •๋ง ๊ฐ„๋‹จํ•œ MQ๊ฐ€ ํ•„์š”ํ•œ ๊ฒฝ์šฐ์— Redis๋ฅผ ์‚ฌ์šฉํ•˜๊ณ  ์ดํ›„ ์‚ฌ์šฉ๋Ÿ‰์ด ๋Š˜์–ด๋‚˜๋ฉด RabbitMQ, Kafka, SQS ๋“ฑ์œผ๋กœ ๋„˜์–ด๊ฐ€๋Š” ๊ฒƒ๋„ ์ข‹์„๊ฒƒ ๊ฐ™๋‹ค.

0 comments on commit 18ee0ab

Please sign in to comment.