Skip to content

Instantly share code, notes, and snippets.

@basilleaf
Created April 22, 2026 22:46
Show Gist options
  • Select an option

  • Save basilleaf/39f1cac7d884116f276047dad481732c to your computer and use it in GitHub Desktop.

Select an option

Save basilleaf/39f1cac7d884116f276047dad481732c to your computer and use it in GitHub Desktop.
Add Upstash Rate Limiting to a Next js app
Go to upstash.com, create a free account, create a Redis database, and grab the UPSTASH_REDIS_REST_URL and UPSTASH_REDIS_REST_TOKEN from the dashboard. Add those to your .env.
check Eviction Enable to evict entries when max data size is reached. ✅
install it:
npm install @upstash/ratelimit @upstash/redis
create the file: lib/ratelimit.ts
```
import { Ratelimit } from "@upstash/ratelimit";
import { Redis } from "@upstash/redis";
const RPM = 10 // 10 requests per minute
export const ratelimit = new Ratelimit({
redis: Redis.fromEnv(),
limiter: Ratelimit.slidingWindow(RPM, "1 m"),
analytics: true,
});
```
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment