Engineering
upstash-ratelimit-ts avatar

upstash-ratelimit-ts

A connectionless, HTTP-based rate limiting SDK for TypeScript, ideal for serverless, edge functions, and distributed environments using Upstash Redis.

Introduction

The upstash-ratelimit-ts SDK provides a robust, connectionless rate-limiting solution designed specifically for modern distributed architectures. By utilizing HTTP rather than traditional TCP connections, this library is optimized for serverless platforms, including AWS Lambda, Vercel Functions, Cloudflare Workers, and Fastly Compute@Edge. It enables developers to easily prevent service abuse, shape traffic, and manage API usage costs across various runtime environments, including Node.js, Deno, and Edge environments.

  • Supports multiple rate-limiting algorithms: Fixed Window, Sliding Window, and Token Bucket, allowing for precise control over request frequency.

  • Native integration with Upstash Redis for low-latency state persistence in global deployments.

  • Analytics support for tracking blocked and successful requests directly via the Upstash dashboard.

  • Built-in traffic protection features including IP-based blocking, user-agent filtering, and country-based access control.

  • Designed for extreme portability, working seamlessly in WebAssembly, browser environments, and serverless compute models where persistent TCP connections are not viable.

  • To get started, initialize the Ratelimit instance by passing your Redis connection string and a chosen algorithm, then apply it to specific routes or API handlers.

  • Ensure environment variables like UPSTASH_REDIS_REST_URL and UPSTASH_REDIS_REST_TOKEN are correctly configured to establish the connectionless session.

  • Use the identifier parameter (such as IP address or user ID) in the limit method to granularly throttle traffic on a per-user basis.

  • Take advantage of the waitUntil function for non-blocking analytics reporting to minimize request latency in serverless environments.

  • Be mindful of Redis cost implications; utilize prefixing to namespace keys if sharing a single Redis instance among multiple applications or services.

Repository Stats

Stars
2,036
Forks
47
Open Issues
5
Language
TypeScript
Default Branch
main
Sync Status
Idle
Last Synced
May 3, 2026, 02:24 AM
View on GitHub