O2O CastAD Backend

인프라 아키텍처 및 비용 산출 문서

1DB 및 서버 부하 분산 방법

Nginx 로드밸런싱, 커넥션 풀 관리, 단계별 수평 확장 전략

현재 구현 현황 (단일 인스턴스)

  • API 커넥션 풀: pool_size=20, max_overflow=20 → 최대 40
  • 백그라운드 풀: pool_size=10, max_overflow=10 → 최대 20
  • 인스턴스당 총 DB 연결: 40 + 20 = 60
  • 풀 리사이클: 280초 (MySQL wait_timeout 300초 이전), pre-ping 활성화

단계별 확장 전략

단계 동시접속 App Server LB DB ( MySQL Flexible)
S1 ~50명 x1 Nginx x1 Burstable B1ms
S2 50~200명 x2~4 Nginx GP D2ds_v4 + Replica x1
S3 200~1,000명 API ServerxN
+ Scheduler
Nginx BC D4ds_v4 + Replica x2 + Redis P1

커넥션 풀 수치 계산

항목 Stage 1 (1대) Stage 2 (4대) Stage 3 (8대)
Main Pool / 인스턴스 20+20 = 40 10+10 = 20 5+5 = 10
BG Pool / 인스턴스 10+10 = 20 5+5 = 10 3+3 = 6
인스턴스당 소계 60 30 16
Primary 총 연결 60 4 x 30 = 120 8 x 16 = 128
max_connections 권장 100 200 300
핵심: JWT Stateless 설계로 Nginx 세션 어피니티 불필요 (round-robin / least_conn). Stage 2부터 Read Replica로 읽기 분산, Redis는 Stage 3에서 캐싱/Rate Limiting 도입.
graph TB
    subgraph S1["Stage 1: ~50명"]
        direction LR
        S1N["Nginx
(Reverse Proxy)"] --> S1A["App Server x1"] S1A --> S1D[" MySQL
Burstable B1ms"] end subgraph S2["Stage 2: 50~200명"] direction LR S2N["Nginx
(Reverse Proxy)"] --> S2API["APP Server
x 1 ~ 2"] S2N --> S2WK["Scheduler
Server"] S2API --> S2P["MySQL BC
Primary
(D4ds_v4)"] S2API --> S2R1["Read Replica
x1"] S2WK --> S2P S2WK --> S2R1 end subgraph S3["Stage 3: 200~1,000명"] direction LR S3N["Nginx
(Reverse Proxy)"] --> S3API["APP Server
x N"] S3N --> S3WK["Scheduler
Server"] S3API --> S3P["MySQL BC
Primary
(D4ds_v4)"] S3API --> S3R1["Read Replica
xN"] S3API --> S3RD["Redis
Premium P1"] S3WK --> S3P S3WK --> S3R1 end S1 ~~~ S2 ~~~ S3 style S1 fill:#0d3320,stroke:#34d399,stroke-width:2px,color:#e1e4ed style S2 fill:#3b2506,stroke:#fb923c,stroke-width:2px,color:#e1e4ed style S3 fill:#3b1010,stroke:#f87171,stroke-width:2px,color:#e1e4ed

2전체 아키텍처 다이어그램

Nginx + FastAPI App Server 구성과 외부 서비스 연동 구조

  • 로드밸런서: Nginx (Reverse Proxy, L7 LB, SSL 종단)
  • App Server: FastAPI (Python 3.13) — Auth, Home, Lyric, Song, Video, Social, SNS, Archive, Admin, Background Worker
  • DB: Database for MySQL Flexible Server — Stage 2+ Read Replica
  • 캐시: Cache for Redis (Stage 3 도입)
  • 콘텐츠 생성: 가사(ChatGPT) → 음악(Suno AI) → 영상(Creatomate) → SNS 업로드
  • 외부 연동: Kakao OAuth, Naver Map/Search API, Blob Storage
graph TB
    Client["클라이언트
(Web / App)"] LB["Nginx
(Reverse Proxy + SSL 종단)"] subgraph APP["App Server (FastAPI)"] direction LR Auth["Auth"] --- Home["Home"] --- Lyric["Lyric"] --- Song["Song"] --- Video["Video"] Social["Social"] --- SNS["SNS"] --- Archive["Archive"] --- Admin["Admin"] --- BG["BG Worker"] end subgraph DB[" MySQL Flexible Server"] direction LR Primary["Primary (R/W)"] Replica["Read Replica"] end subgraph AI["AI 콘텐츠 생성 파이프라인"] direction LR ChatGPT["ChatGPT
(가사 생성)"] Suno["Suno AI
(음악 생성)"] Creatomate["Creatomate
(영상 생성)"] ChatGPT --> Suno --> Creatomate end subgraph EXT["외부 서비스"] direction LR Blob[" Blob
Storage"] Kakao["Kakao
OAuth"] YT["YouTube /
Instagram"] Naver["Naver Map /
Search API"] end Redis[" Cache for Redis
(Stage 3 도입)"] Client -->|HTTPS| LB LB --> APP APP --> Primary APP -->|"읽기 전용"| Replica APP -.->|"Stage 3"| Redis APP --> AI APP --> Blob APP --> Kakao APP --> YT APP --> Naver style Client fill:#1a3a1a,stroke:#34d399,stroke-width:2px,color:#e1e4ed style LB fill:#1a3a1a,stroke:#34d399,stroke-width:2px,color:#e1e4ed style APP fill:#1a2744,stroke:#6c8cff,stroke-width:2px,color:#e1e4ed style DB fill:#2a1f00,stroke:#fb923c,stroke-width:2px,color:#e1e4ed style AI fill:#2a0f2a,stroke:#a78bfa,stroke-width:2px,color:#e1e4ed style EXT fill:#0d2a2a,stroke:#34d399,stroke-width:2px,color:#e1e4ed style Redis fill:#3b1010,stroke:#f87171,stroke-width:1px,color:#e1e4ed

전체 시스템 아키텍처 구성도

콘텐츠 생성 흐름: 사용자 요청 → Naver 크롤링 → ChatGPT 가사 생성 → Suno AI 음악 생성 → Creatomate 영상 생성 → Blob 저장 → YouTube/Instagram 업로드

3예상 리소스 및 비용

기반 단계별 월 예상 비용 (인프라 + 외부 API)

Stage 1 · 동시 ~50명
$170~390
약 22~51만원/월
Stage 2 · 동시 50~200명
$960~2,160
약 125~280만원/월
Stage 3 · 동시 200~1,000명
$3,850~8,500
약 500~1,100만원/월

항목별 비용 상세

항목 Stage 1 Stage 2 Stage 3
App Server $50~70 $200~400 $600~1,000
Nginx - 포함 / VM $15~30 VM $30~60
MySQL Primary B1ms $15~25 GP $130~160 BC $350~450
MySQL Replica - GP x1 $130~160 BC x2 $260~360
Redis - - P1 $225
스토리지/네트워크 $10~20 $55~100 $160~270
AI API (합계) $90~280 $400~1,250 $2,100~5,800

DB 용량 예측 (1년 후)

Stage 1 (500명) Stage 2 (5,000명) Stage 3 (50,000명)
DB 용량 ~1.2GB ~12GB ~120GB
Blob 스토리지 ~1.1TB ~11TB ~110TB
MySQL 추천 32GB SSD 128GB SSD 512GB SSD
비용 최적화 팁: 3rd party 의존도 낮춰야함
Blob Lifecycle Policy (30일 미접근 → Cool 티어),
pie title Stage 3 월 비용 구성 비중
    "App Server (APP+Scheduler)" : 800
    "Nginx" : 45
    "MySQL Primary" : 400
    "MySQL Replica x2" : 310
    "Redis Premium" : 225
    "스토리지/네트워크" : 215
    "OpenAI API" : 550
    "Suno AI" : 1400
    "Creatomate" : 2000
            

Stage 3 월간 비용 구성 비율 — AI API 비중이 전체의 약 66%