Communitygithub.com

속도 제한

토큰 버킷, 슬라이딩 윈도우, 사용자/IP별 제한, Redis 기반, Upstash 패턴.

속도 제한란 무엇인가요?

이 스킬은 API 엔드포인트에 대한 강력한 속도 제한을 구현하기 위한 모범 사례와 패턴을 제공합니다. 토큰 버킷과 슬라이딩 윈도우 알고리즘을 지원하며, API 키 또는 IP를 기반으로 호출자를 식별하여 인증된 경로에서는 IP만 사용하지 않도록 합니다. 서버리스 환경을 위해 Upstash의 @upstash/ratelimit 라이브러리를 권장하며, Redis 원자성과 슬라이딩 윈도우를 기본적으로 처리합니다. 속도 제한은 미들웨어로 전역 적용하고, 경로별로 더 엄격한 제한을 덮어쓸 수 있도록 설계되었습니다. Next.js에서는 미들웨어 또는 API 라우트 핸들러에서 제한을 적용하고, React 컴포넌트에서는 피해야 합니다. 또한, 무료/프로/엔터프라이즈 계층별로 제한을 분리하고, 호출자 식별과 함께 속도 제한 히트를 로깅하여 남용 패턴을 조기에 감지할 것을 권장합니다.

지원 대상~Claude Code~Codex CLI~Cursor
npx skills add https://github.com/YepAPI/skills/tree/HEAD/skills/rate-limiting

즐겨 사용하는 AI에게 물어보기

이 에이전트 스킬이 미리 로드된 새 채팅을 엽니다.

문서

속도 제한은(는) 무엇을 하나요?

규칙

  • API 엔드포인트에는 토큰 버킷, 인증/로그인 경로에는 슬라이딩 윈도우 사용
  • 호출자는 API 키로 먼저 식별하고, 실패 시 IP로 대체 — 인증된 경로에서는 IP만 사용 금지
  • 429 Too Many Requests 응답에 Retry-After 헤더(초)와 X-RateLimit-Remaining 헤더 포함
  • 카운터는 Redis(또는 서버리스의 경우 Upstash)에 저장 — 다중 인스턴스 배포에서 인메모리 사용 금지
  • 적절한 기본값 설정: 일반 API는 분당 100회, 인증은 분당 5회, 읽기는 분당 1000회
  • 서버리스의 경우 @upstash/ratelimit 사용 — Redis 원자성과 슬라이딩 윈도우를 기본적으로 처리
  • 미들웨어로 속도 제한 구현 — 전역 적용, 경로별로 더 엄격한 제한으로 재정의 가능
  • Next.js: middleware.ts 또는 API 라우트 핸들러에서 속도 제한, React 컴포넌트에서는 금지
  • 계층별 제한 분리: 무료, 프로, 엔터프라이즈 — 계층은 JWT 또는 데이터베이스 조회로 저장
  • 호출자 식별과 함께 속도 제한 히트 로깅 — 남용 패턴 조기 발견

패턴

// Upstash 서버리스 패턴
import { Ratelimit } from "@upstash/ratelimit";
import { Redis } from "@upstash/redis";

const ratelimit = new Ratelimit({
  redis: Redis.fromEnv(),
  limiter: Ratelimit.slidingWindow(10, "10 s"),
  analytics: true,
});

const { success, limit, remaining, reset } = await ratelimit.limit(identifier);

피해야 할 것

  • 서버리스 또는 다중 인스턴스 설정에서 인메모리 속도 제한 — 호출 간 상태 손실
  • 애플리케이션 레이어에서만 속도 제한 — CDN/엣지 제한도 추가(Cloudflare, Vercel)
  • 과도하게 공격적인 제한으로 합법적인 사용자 차단 — 관대하게 시작하고 데이터 기반으로 강화
  • 웹훅 및 공개 양식 제출에 대한 속도 제한 누락

Individual skills in this repo

This repo contains 20 individual skills — each has its own dedicated page.

YepAPI/skills

WCAG 2.1 AA — semantic HTML, keyboard navigation, screen readers.

YepAPI/skills

Experiment setup, variant splitting, statistical significance, and feature flag integration.

YepAPI/skills

CRUD generators, data tables, user management, role-based access, and bulk operations.

YepAPI/skills

Monitor what ChatGPT and Gemini say about your brand using YepAPI.

YepAPI/skills

Queue workers with BullMQ/Inngest/Trigger.dev, job retries, dead letter queues, concurrency.

YepAPI/skills

Commander.js, interactive prompts with Clack, spinners, colors, config files, exit codes, and npm publishing.

YepAPI/skills

cmdk integration, Cmd+K trigger, fuzzy search, grouped actions, keyboard navigation, and dynamic action registration.

YepAPI/skills

Content planning with trend and sentiment data from YepAPI.

YepAPI/skills

Content calendar, keyword-driven planning, and content briefs.

YepAPI/skills

Theme switching with CSS variables, system preference detection, next-themes, and persistence.

YepAPI/skills

Threaded comments, @mentions, reactions, moderation queue, optimistic UI, and cursor pagination.

YepAPI/skills

Competitive analysis between domains using YepAPI.

YepAPI/skills

Layout grids, KPI cards, data tables with sorting/filtering, sidebar navigation, and responsive breakpoints.

YepAPI/skills

Data encryption — TLS everywhere, AES-256-GCM for PII, bcrypt passwords, encrypted backups.

YepAPI/skills

Chart patterns with Recharts/Nivo/D3, responsive containers, color scales, and accessibility.

YepAPI/skills

Drizzle schema definition, push vs migrate, type-safe queries, relations, transactions, and prepared statements.

YepAPI/skills

Upload handling, resize/compress, CDN delivery, blur placeholders, and next/image patterns.

YepAPI/skills

Local business and Google Maps research using YepAPI.

YepAPI/skills

Cursor-based pagination, IntersectionObserver, virtualized lists with @tanstack/react-virtual, and scroll position restoration.

YepAPI/skills

Chat UI components, streaming responses with AI SDK, context window management, and RAG patterns.

관련 스킬