본문으로 건너뛰기
김신건의 로그

[Pattern] API Gateway: BFF, 라우팅, auth, rate limit

· 수정 · 📖 약 1분 · 441자/단어 #api-gateway #microservices #backend #infrastructure
API Gateway, BFF, Backend for Frontend, Kong, Tyk, AWS API Gateway, Envoy

정의

API Gateway = 클라이언트와 마이크로서비스 사이의 단일 진입점. 라우팅, auth, rate limit, transformation, monitoring 의 cross-cutting 책임 을 모음.

역할

flowchart LR
    Client[Mobile / Web / IoT] --> GW[API Gateway]
    GW -->|/users/*| US[User Service]
    GW -->|/orders/*| OS[Order Service]
    GW -->|/payments/*| PS[Payment Service]
    GW -.cross-cutting.-> Auth[Auth]
    GW -.cross-cutting.-> RL[Rate Limit]
    GW -.cross-cutting.-> Log[Logging]
    GW -.cross-cutting.-> Cache[Cache]
    GW -.cross-cutting.-> Transform[Request/Response transform]

책임 카탈로그

책임예시
라우팅path / header / host 기준
인증 / 인가JWT 검증, OAuth, API key
Rate limitingper-API key, per-IP
Transformationrequest/response 변환 (gRPC↔REST)
캐싱응답 캐시
Load balancing백엔드 분산
Circuit breaker백엔드 다운 시 차단
Logging / metrics중앙 집계
WAFSQLi, XSS 차단
TLS termination인증서 관리
VersioningURL / 헤더 기반 분기

BFF (Backend For Frontend)

flowchart LR
    iOS[iOS App] --> iOSGW[iOS BFF]
    Web[Web App] --> WebGW[Web BFF]
    Android[Android App] --> AnGW[Android BFF]
    iOSGW & WebGW & AnGW --> Services[(공통 services)]

각 클라이언트 종류마다 별도 gateway. 클라이언트 별 응답 형식 / 페이지네이션 / 압축 차이 흡수. 모바일 = 작은 응답, 웹 = 큰 응답.

API Gateway vs Service Mesh

항목API GatewayService Mesh
위치외부 ↔ 내부 경계 (north-south)내부 ↔ 내부 (east-west)
책임인증, transformation, public APImTLS, retry, circuit, observability
클라이언트 인지직접 호출sidecar 자동
Kong, AWS API Gateway, EnvoyIstio, Linkerd

NOTE

둘 다 운영하는 경우 가 흔하다. gateway 가 north-south, mesh 가 east-west.

도구 비교

도구종류강점
KongOSS gatewayplugin 생태계
TykOSS gateway옵션
EnvoyProxygRPC, L7, mesh 토대
AWS API GatewayManagedLambda 통합
Cloudflare WorkersEdge글로벌
ApigeeEnterprise (Google)엔터프라이즈
Apollo RouterGraphQLfederation

패턴: GraphQL Federation Gateway

flowchart TB
    Client --> Router[Apollo Router]
    Router --> A[User subgraph]
    Router --> B[Order subgraph]
    Router --> C[Payment subgraph]

자세한 건 graphql 참고.

흔한 함정

WARNING

  1. Gateway 가 모든 비즈니스 로직 흡수 = monolith 의 재림. cross-cutting 만.
  2. 단일 gateway 의 bottleneck = HA + auto-scaling 필수.
  3. Auth 검증 백엔드 마다 다시 = gateway 가 검증 → 백엔드는 trust. 단 zero-trust 환경에서는 백엔드도 검증.
  4. Rate limit 의 분산 상태 = 단일 노드 카운터 = race. 중앙 store (Redis) + sliding window.

관련 위키

이 글의 용어 (6개)
[API Design] GraphQL: 단일 endpoint, N+1, persisted queriesapi-design
정의 GraphQL (Facebook, 2015) 은 클라이언트가 필요한 필드만 명시 하는 query language + 런타임. 단일 endpoint, typed schema,…
[Auth] JWT: 구조, 서명, 만료, refresh tokenauth-security
정의 JWT (JSON Web Token) (RFC 7519) 은 base64url 인코딩된 JSON + 서명 형태의 self-contained token. 서버가 세션 저장 없…
[Auth] mTLS (Mutual TLS): 양방향 인증서 인증auth-security
정의 mTLS (Mutual TLS) 는 서버뿐 아니라 클라이언트도 TLS 인증서로 자기 신분 증명. 일반 TLS = 서버 인증만, mTLS = 양방향. 활용: 서비스 메시 (I…
[Auth] OAuth 2.0 / 2.1: Authorization Code + PKCEauth-security
정의 OAuth 2.0 (RFC 6749, 2012) 은 제3자 앱이 사용자 동의로 자원에 접근 하게 하는 권한 위임 프레임워크. 인증 (authentication) 이 아니라 …
[Network] Load Balancer: L4 vs L7, 알고리즘, sticky sessionnetwork
정의 Load Balancer 는 트래픽을 여러 백엔드로 분산 하는 인프라. 수평 확장 + 가용성 + 무중단 배포 의 토대. L4 vs L7 | 구분 | L4 (Transport…
[Pattern] Microservices vs Monolith: 언제 분리, 언제 통합distributed-systems
정의 | | Monolith | Modular Monolith | Microservices | |---|---|---|---| | 배포 단위 | 1개 | 1개 (모듈 명확) | …

💬 댓글

사이트 검색 / 명령어

검색

스크롤 = 확대/축소 · 드래그 = 이동 · 0 = 원래 크기 · ESC = 닫기