사용 기술
NestJS, Socket.IO, Redis, Docker Compose, Node Cluster, Artillery …. ETC
현재 개발하고 있는 메타버스 플랫폼의 채팅을 웹소켓으로 전환하고자 개발을 시작하였고
추후 서비스 확장을 염두해두고 확장성 있는 구조로 개발해야 했습니다.
이번 시리즈에선, 제가 했던 고민들을 풀어보며 확장성 있는 구조로 개발해보는 시간을 가져보려고 합니다.
저는 이번 시리즈에서 아래를 중점으로 생각하며 개발하였습니다.
스케일 아웃이 되어도 문제 없이 동작하며 각 서버별로 세션 및 메세지들이 동기화 되도록하고 Node.JS의 단점인 싱글 프로세스의 문제를 해결하고 서버 리소스를 낭비없이 사용하도록 합니다.
Docker-Compose 로 Redis 환경을 구성합니다.
# docker-compose.yml
version: '3.7'
services:
redis:
image: redis:alpine
command: redis-server --port 6379
container_name: redis_boot
hostname: redis_boot
labels:
- "name=redis"
- "mode=standalone"
ports:
- 6379:6379
docker-compose up -d 명령어를 사용하여 Redis Docker Image를 실행합니다.
$ docker-compose up -d
Creating network "nestjs-socketio_default" with the default driver
Pulling redis (redis:)...
latest: Pulling from library/redis
a076a628af6f: Pull complete
f40dd07fe7be: Pull complete
ce21c8a3dbee: Pull complete
ee99c35818f8: Pull complete
56b9a72e68ff: Pull complete
3f703e7f380f: Pull complete
Digest: sha256:0f97c1c9daf5b69b93390ccbe8d3e2913649ec4801fd0882c72bf7cad3a13494
Status: Downloaded newer image for redis:latest
Creating redis ... done
$ docker ps
로 상태를 확인합니다.
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
158a17e10843 redis "docker-entrypoint.s…" 7 seconds ago Up 6 seconds 0.0.0.0:10300->6379/tcp redis