Back to templates

Template details

Ratelimit with Upstash Redis Example

Example app wiring @upstash/ratelimit to Upstash Redis, with npm local dev and one-command Vercel deployment.

About this template

@upstash/ratelimit & @upstash/redis example is a small server-side reference project from the Upstash examples repository that connects the @upstash/ratelimit library to an Upstash Redis instance, runs locally through npm scripts, and deploys to Vercel with the Vercel CLI.

What is the @upstash/ratelimit & @upstash/redis example?

This example demonstrates using @upstash/ratelimit together with @upstash/redis, the two npm packages it pairs. You supply Upstash Redis credentials as environment variables, and the application uses them at runtime to enforce rate limits through the @upstash/ratelimit library. It lives in the Upstash examples repository (about 42 stars), whose stated description is "Examples how to use Upstash with various tech", so it is one entry in a collection rather than a standalone product.

How does it work?

Running the example takes five steps: copy the example env file with cp .env.local.example .env.local, create an Upstash Redis instance, set the environment variables in the new file using the instance's credentials, install dependencies with npm install, and start the app with npm run dev. Deployment from the same directory is a single vercel command through the Vercel CLI.

Key Features

  • @upstash/ratelimit integration — the example is built around the @upstash/ratelimit package, applied against a Redis backend rather than in-memory state.
  • Upstash Redis backend — rate limit state is stored in an Upstash Redis instance that you create and connect via credentials.
  • Environment file template — a committed .env.local.example is copied to .env.local, which is where the Upstash Redis connection values are pasted.
  • npm workflow — npm install installs dependencies and npm run dev starts the local development server.
  • One-command Vercel deployment — running vercel from the project directory builds and deploys the app to Vercel.
  • Part of a larger examples collection — the repository collects Upstash usage examples across multiple tech stacks, so this sample shares conventions with the others.

Who should use the rate limit example?

  • Node developers adding rate limiting: copy the setup pattern to attach @upstash/ratelimit to an existing API route or handler instead of writing the Redis wiring from scratch.
  • Serverless and edge teams: use the Upstash Redis credential setup as a starting point for rate limiting where in-process memory counters do not persist across invocations.
  • Vercel deployers: follow the vercel CLI path, including the note that a newly created project may need its environment variables set and a redeploy.
  • Evaluators of Upstash: check how @upstash/ratelimit and @upstash/redis fit together before committing an app to the stack.

Use cases

  • API protection: wire the example's packages into a public HTTP endpoint so repeated requests from one client are counted in Upstash Redis and rejected past your configured threshold.
  • Login and signup throttling: reuse the environment-variable and client setup to limit repeated authentication attempts from a single source.
  • Prototyping before production: run npm run dev locally against a free-to-create Upstash Redis instance to validate the limiting behavior, then push the same configuration to Vercel.

FAQ

Do I need an Upstash Redis instance to run this example?

Yes. The application reads Upstash Redis credentials from the environment, so you must create an Upstash Redis instance, copy .env.local.example to .env.local, and place the credentials there before npm run dev will work.

How do I deploy this example to Vercel?

Run the vercel command from the project directory. The README notes that if you create a new project during that step, you may need to set the environment variables on the project and redeploy the app for the Redis connection to work.

Does the README document specific rate limit rules?

No. It covers environment setup, local development with npm, and Vercel deployment only. Specific algorithms, time windows, and request thresholds are configured by you in the code rather than described on the page.

Is this a full application or a minimal example?

It is a minimal example whose stated purpose is demonstrating @upstash/ratelimit with Upstash Redis. There is no documented UI, database schema, or feature list beyond the setup and deploy instructions.

screenshot of Ratelimit with Upstash Redis Example on template0.com