Rate Limiting
Learn how to set up and use Upstash Redis for efficient rate limiting
Dirstarter uses Upstash Redis with their @upstash/ratelimit
package for efficient rate limiting. This combination provides a serverless-friendly solution for protecting your APIs and routes from abuse.
This integration is optional. If you don't want to use rate limiting, you can skip this section.
Upstash Redis
Upstash Redis is a serverless Redis database that offers:
- Serverless architecture
- Global distribution
- TypeScript support
- Built-in rate limiting
- Edge compatibility
- Pay-per-use pricing
Setup
- Create an Upstash account at upstash.com
- Create a new Redis database
- Get your Redis URL and token from the dashboard
- Add the following environment variables:
Alternative Redis Hosting
While Upstash is our recommended choice, you can use any Redis provider that supports the REST API. Here are some popular options:
When using a non-Upstash Redis provider, make sure it supports the REST API and has proper authentication. Some providers might require additional configuration or have different connection string formats.
Usage
The boilerplate provides a simple way to implement rate limiting:
Implementation
The boilerplate includes pre-configured rate limiters for different actions:
Use the rate limiter in your server actions:
Last updated on