upstash-ratelimit
Rules, standards, and references for rate limiting in serverless environments using Upstash Ratelimit. Use when implementing rate limiting, configuring Upstash Redis, or handling request blocking.
- License 许可
- MIT
- 最近更新
- 2026-08-02
- Stars
- ★ 0
- Forks
- 0
01 前言 Front Matter
- name
- upstash-ratelimit
- license
- MIT
- metadata
- { "author": "ngxc", "version": "1.0.0" }
- description
- Rules, standards, and references for rate limiting in serverless environments using Upstash Ratelimit. Use when implementing rate limiting, configuring Upstash Redis, or handling request blocking.
- argument-hint
- [--limit <number>] [--window <string>]
02 资源文件 7
- 参考文档AGENTS.md4.1 KB
- 参考文档references/algo-sliding-window-over-fixed.md1.7 KB
- 参考文档references/feat-deny-list-protection.md2.5 KB
- 参考文档references/feat-ephemeral-cache.md2.4 KB
- 参考文档references/feat-graceful-timeout.md2.1 KB
- 参考文档references/setup-await-pending-promises.md2.6 KB
- 参考文档references/setup-lazy-initialization.md3.2 KB
03 SKILL.md 正文
Upstash Rate Limiting Guide
Comprehensive guide for rate limiting in stateless, serverless, and edge environments using @upstash/ratelimit.
Core Principles
- Stateless Compliance: Never use in-memory rate limiting (
RateLimiterMemory) in serverless environments (Vercel, AWS Lambda, Cloudflare Workers). Use@upstash/ratelimitwith Redis REST connections. - Graceful Fallback: Handle Redis timeouts and missing credentials gracefully so that infrastructure issues do not crash the application or block legitimate users.
- Identifier Granularity: Rate limit based on the narrowest specific identifier (e.g., user ID, API key, or hashed client IP) to avoid blanket blocking.
- Asynchronous Chores: Wait for background analytics or MultiRegion synchronization promises (
pending) to resolve before returning responses in serverless contexts.
When to Apply
Reference these guidelines when:
- Enforcing rate limits on public or sensitive API routes and Server Actions.
- Configuring Upstash Redis connection clients.
- Implementing IP-based deny lists or traffic protection.
- Optimizing rate limiting performance and costs in Cloudflare Workers or Vercel Edge.
Rule Categories by Priority
| Priority | Category | Impact | Prefix | Rules |
|---|---|---|---|---|
| 1 | Connection & Setup | CRITICAL | setup- |
2 |
| 2 | Algorithm Selection | HIGH | algo- |
1 |
| 3 | Features & Optimization | HIGH | feat- |
3 |
Quick Reference
1. Connection & Setup (CRITICAL)
- setup-lazy-initialization - Lazily initialize connection clients.
- setup-await-pending-promises - Await pending promises in serverless.
2. Algorithm Selection (HIGH)
- algo-sliding-window-over-fixed - Prefer sliding window for boundary accuracy.
3. Features & Optimization (HIGH)
- feat-ephemeral-cache - Enable ephemeral caching for hot containers.
- feat-graceful-timeout - Configure client-side timeouts for fallback.
- feat-deny-list-protection - Enable protection deny lists.
How to Use
Read individual reference files for detailed guidelines, configurations, and code examples:
- setup-lazy-initialization
- setup-await-pending-promises
- algo-sliding-window-over-fixed
- feat-ephemeral-cache
- feat-graceful-timeout
- feat-deny-list-protection
Full Compiled Document
For the complete guide with all rules expanded: AGENTS.md
References
04 同仓库更多 Skills
zustand
Rules and standards for state management using Zustand in React and Next.js. Use when implementing client-side stores, persistence with localStorage, or preventing SSR hydration mismatch.
zod
Zod v4 schema validation best practices. Use when defining schemas, utilizing safeParse, or customizing error messages.
ui-design
UI/UX and frontend design best practices guidelines (formerly frontend-design). This skill should be used when writing, reviewing, or designing frontend code to ensure accessibility, performance, and usability. Triggers on tasks involving HTML structure, CSS styling, responsive layouts, form design, animations, or accessibility improvements.
typescript
TypeScript performance, tsconfig, type errors, async patterns — triggered when the user asks to "optimize TypeScript performance", "speed up tsc compilation", "configure tsconfig.json", "fix type errors", "improve async patterns", or encounters TS errors (TS2322, TS2339, "is not assignable to"). Also triggers on .ts, .tsx, .d.ts file work involving type definitions, module organization, or memory management. Does NOT cover TypeScript basics, framework-specific patterns, or testing.
typescript-refactor
TypeScript and TSX refactoring and modernization guidelines from a principal specialist perspective, current to TypeScript 6.0 and React 19. This skill should be used when refactoring, reviewing, or modernizing TypeScript or React/TSX code for type safety, compiler performance, and idiomatic patterns. Triggers on tasks involving type architecture, narrowing, generics, discriminated unions, error handling, React component and hook typing, or migration to modern TypeScript features (satisfies, using, const type parameters, inferred type predicates, isolatedDeclarations, erasable syntax, import attributes).
typescript-advanced-patterns
Advanced TypeScript — type-level programming, library/DSL APIs, declaration merging, modern language features at depth (decorators, using, const T, NoInfer, variance), and feature implementation patterns built on advanced types. Trigger on tasks involving recursive conditional types, infer patterns, mapped-type key remapping, variadic tuples, fluent builders with phantom state, schema-first inference (Zod/Valibot), end-to-end-typed API clients, finite state machines, module augmentation, and library-publishing concerns. Trigger even when the user does not say "advanced" — if the work involves type-level algorithms, library-author API design, or going beyond surface-level uses of TS 5.x features, this is the skill. Assumes the reader has absorbed the `typescript-refactor` skill — this one extends those patterns at depth, never restates them.