- Implemented JWT authentication in Console backend - Added .env file for environment variable management - Updated docker-compose to use .env variables - Created authentication endpoints (login/logout/me) - Added protected route middleware - Created ARCHITECTURE.md with Kafka as main messaging platform - Defined Kafka for both events and task queues - Redis dedicated for caching and session management Test credentials: - admin/admin123 - user/user123 🤖 Generated with Claude Code Co-Authored-By: Claude <noreply@anthropic.com>
4.2 KiB
4.2 KiB
Site11 Microservices Architecture
시스템 아키텍처 개요
메시징 및 데이터 처리 시스템
1. Apache Kafka - 통합 메시징 플랫폼
- 역할: 이벤트 스트리밍 + 작업 큐 + 메시지 버스
- 사용 사례:
- 서비스 간 이벤트 발행/구독
- 비동기 작업 큐 (Celery 대체)
- 사용자 활동 로그 스트리밍
- 실시간 데이터 파이프라인
- 이벤트 소싱 패턴 구현
- CQRS (Command Query Responsibility Segregation)
- 백그라운드 작업 처리
2. Redis - 인메모리 데이터 스토어
- 역할: 캐싱 및 세션 관리 전용
- 사용 사례:
- API 응답 캐싱
- 사용자 세션 저장
- Rate limiting
- 실시간 리더보드/카운터
- 임시 데이터 저장
3. MongoDB - Document Database
- 역할: 주요 데이터 영속성
- 사용 사례:
- 서비스별 도메인 데이터
- 유연한 스키마 관리
- 이벤트 저장소
서비스 통신 패턴
동기 통신 (REST API)
Client → Nginx → Console (API Gateway) → Microservice
- 즉각적인 응답이 필요한 경우
- CRUD 작업
- 실시간 데이터 조회
비동기 통신 (Kafka Events)
Service A → Kafka Topic → Service B, C, D
- 서비스 간 느슨한 결합
- 이벤트 기반 아키텍처
- 확장 가능한 처리
캐싱 전략 (Redis)
Request → Check Redis Cache → Hit? Return : Fetch from DB → Store in Redis → Return
- 응답 시간 개선
- 데이터베이스 부하 감소
- 세션 관리
이벤트 플로우 예시
사용자 등록 플로우
- API Request: Client → Console → Users Service
- User Created Event: Users Service → Kafka
- Event Consumers:
- Statistics Service: 사용자 통계 업데이트
- Email Service: 환영 이메일 발송
- Analytics Service: 가입 분석
- Cache Update: Redis에 사용자 정보 캐싱
이미지 업로드 플로우
- Upload Request: Client → Console → Images Service
- Image Uploaded Event: Images Service → Kafka
- Event Processing:
- Thumbnail Service: 썸네일 생성
- ML Service: 이미지 분석
- Statistics Service: 업로드 통계
- Job Queue: Redis/Celery로 백그라운드 처리
Kafka Topics 구조 (예정)
Event Topics (이벤트 스트리밍)
# User Domain
user.created
user.updated
user.deleted
user.login
# Image Domain
image.uploaded
image.processed
image.deleted
# Application Domain
app.registered
app.updated
app.deployed
# System Events
service.health
service.error
audit.log
Task Queue Topics (작업 큐)
# Background Jobs
tasks.email.send
tasks.image.resize
tasks.report.generate
tasks.data.export
tasks.notification.push
# Scheduled Jobs
tasks.cleanup.expired
tasks.backup.database
tasks.analytics.aggregate
Redis 사용 패턴
1. 캐싱 계층
- Key:
cache:users:{user_id} - TTL: 3600초
- 패턴: Cache-Aside
2. 세션 관리
- Key:
session:{token} - TTL: 1800초
- 데이터: 사용자 정보, 권한
3. Rate Limiting
- Key:
rate_limit:{user_id}:{endpoint} - Window: Sliding window
- Limit: 100 requests/minute
4. 작업 큐 (Celery)
- Queue:
celery:tasks - Priority Queue 지원
- Dead Letter Queue
구현 로드맵
Phase 1 (현재)
- ✅ 기본 서비스 구조
- ✅ MongoDB 연동
- ✅ Redis 설치
- 🔄 JWT 인증
Phase 2 (Step 6-7)
- Kafka 클러스터 설정
- 기본 Producer/Consumer 구현
- Event Schema 정의
- Redis 캐싱 전략 구현
Phase 3 (Step 8+)
- Event Sourcing 패턴
- CQRS 구현
- Saga 패턴 (분산 트랜잭션)
- 모니터링 대시보드
기술 스택
메시징 & 스트리밍
- Kafka: Event streaming
- Redis: Caching, Queue, Pub/Sub
- Confluent Schema Registry: Schema 관리 (향후)
백엔드
- FastAPI: REST API
- Celery: 비동기 작업 처리
- kafka-python: Kafka 클라이언트
데이터베이스
- MongoDB: Document store
- Redis: In-memory cache
모니터링 (향후)
- Kafka Manager: Kafka 클러스터 관리
- RedisInsight: Redis 모니터링
- Prometheus + Grafana: 메트릭 수집/시각화