{
  "schema_version": 2,
  "id": "develop/use-cases/rate-limiter",
  "title": "Redis rate limiter",
  "url": "https://redis.io/docs/latest/develop/use-cases/rate-limiter/",
  "summary": "Enforce request quotas across distributed services with Redis",
  "tags": [
    "docs",
    "develop",
    "stack",
    "oss",
    "rs",
    "rc"
  ],
  "last_updated": "2026-09-17T10:28:27+01:00",
  "children": [
    {
      "id": "develop/use-cases/rate-limiter/redis-py",
      "summary": "Implement a token bucket rate limiter with Redis and redis-py",
      "title": "Token bucket rate limiter with Redis and redis-py",
      "url": "https://redis.io/docs/latest/develop/use-cases/rate-limiter/redis-py/"
    },
    {
      "id": "develop/use-cases/rate-limiter/nodejs",
      "summary": "Implement a token bucket rate limiter using Redis and Lua scripts in Node.js",
      "title": "Token bucket rate limiter with Redis and Node.js",
      "url": "https://redis.io/docs/latest/develop/use-cases/rate-limiter/nodejs/"
    },
    {
      "id": "develop/use-cases/rate-limiter/go",
      "summary": "Implement a token bucket rate limiter using Redis and Lua scripts in Go",
      "title": "Token bucket rate limiter with Redis and Go",
      "url": "https://redis.io/docs/latest/develop/use-cases/rate-limiter/go/"
    },
    {
      "id": "develop/use-cases/rate-limiter/java-jedis",
      "summary": "Implement a token bucket rate limiter using Redis and Lua scripts in Java",
      "title": "Token bucket rate limiter with Redis and Java",
      "url": "https://redis.io/docs/latest/develop/use-cases/rate-limiter/java-jedis/"
    },
    {
      "id": "develop/use-cases/rate-limiter/dotnet",
      "summary": "Implement a token bucket rate limiter using Redis and Lua scripts in .NET",
      "title": "Token bucket rate limiter with Redis and .NET",
      "url": "https://redis.io/docs/latest/develop/use-cases/rate-limiter/dotnet/"
    },
    {
      "id": "develop/use-cases/rate-limiter/java-lettuce",
      "summary": "Implement a token bucket rate limiter using Redis and Lua scripts in Java with Lettuce",
      "title": "Token bucket rate limiter with Redis and Java (Lettuce)",
      "url": "https://redis.io/docs/latest/develop/use-cases/rate-limiter/java-lettuce/"
    },
    {
      "id": "develop/use-cases/rate-limiter/php",
      "summary": "Implement a token bucket rate limiter using Redis and Lua scripts in PHP",
      "title": "Token bucket rate limiter with Redis and PHP",
      "url": "https://redis.io/docs/latest/develop/use-cases/rate-limiter/php/"
    },
    {
      "id": "develop/use-cases/rate-limiter/ruby",
      "summary": "Implement a token bucket rate limiter using Redis and Lua scripts in Ruby",
      "title": "Token bucket rate limiter with Redis and Ruby",
      "url": "https://redis.io/docs/latest/develop/use-cases/rate-limiter/ruby/"
    },
    {
      "id": "develop/use-cases/rate-limiter/rust",
      "summary": "Implement a token bucket rate limiter using Redis and Lua scripts in Rust",
      "title": "Token bucket rate limiter with Redis and Rust",
      "url": "https://redis.io/docs/latest/develop/use-cases/rate-limiter/rust/"
    }
  ],
  "page_type": "content",
  "content_hash": "b52f3177d50a32949bfa872745f1a42a371acc5ecc7a6376f695f364a7119808",
  "sections": [
    {
      "id": "when-to-use-a-redis-rate-limiter",
      "title": "When to use a Redis rate limiter",
      "role": "overview",
      "text": "Use a Redis rate limiter when you need to enforce per-user, per-API, or per-tenant request quotas consistently across distributed service instances."
    },
    {
      "id": "why-the-problem-is-hard",
      "title": "Why the problem is hard",
      "role": "content",
      "text": "APIs and services get overloaded by traffic spikes, abusive clients, or misconfigured integrations. Without rate limiting, downstream systems — databases, third-party APIs, LLM providers, payment gateways — become unavailable or generate unbounded costs.\n\nLocal per-process counters break behind load balancers: the same client bypasses limits by hitting different instances. The rate limiter needs a centralized store fast enough to sit on the request path without adding meaningful latency."
    },
    {
      "id": "what-you-can-expect-from-a-redis-solution",
      "title": "What you can expect from a Redis solution",
      "role": "content",
      "text": "You can:\n\n-   Enforce quotas per user, IP, API key, tenant, or model across all instances.\n-   Run fixed window, sliding window, and token bucket algorithms on a single Redis deployment.\n-   Add a synchronous rate check to any gateway or service on the request path.\n-   Protect downstream systems from overload without adding meaningful latency."
    },
    {
      "id": "how-redis-supports-the-solution",
      "title": "How Redis supports the solution",
      "role": "content",
      "text": "In practice, a Redis rate limiter is a single shared store that every service instance queries on every request, returning an allow/deny decision in sub-millisecond time. Counters live behind keys scoped to the dimension you are limiting on (user, IP, API key, tenant, model), and time windows are cleaned up by Redis itself.\n\nRedis provides the following features that make it a good fit for rate limiting:\n\n-   [`INCR`](https://redis.io/docs/latest/commands/incr) and [`EXPIRE`](https://redis.io/docs/latest/commands/expire)\n    give you atomic fixed-window counters with automatic time-window cleanup.\n-   [Hashes](https://redis.io/docs/latest/develop/data-types/hashes),\n    [sorted sets](https://redis.io/docs/latest/develop/data-types/sorted-sets), and\n    [strings](https://redis.io/docs/latest/develop/data-types/strings) cover the data shapes needed for\n    sliding window and token bucket algorithms.\n-   Hash field expiration in Redis 8\n    ([`HEXPIRE`](https://redis.io/docs/latest/commands/hexpire)) further simplifies time-bound\n    rate limiting at the field level.\n-   [Lua scripting](https://redis.io/docs/latest/develop/programmability/eval-intro) with\n    [`EVAL`](https://redis.io/docs/latest/commands/eval) keeps the read-decide-update cycle atomic, so\n    concurrent requests cannot double-spend tokens or lose counter updates.\n-   Sub-millisecond latency means the rate check sits on the synchronous request path\n    without adding meaningful delay, even at millions of requests per second.\n-   [Active-Active replication](https://redis.io/docs/latest/operate/rs/databases/active-active)\n    provides CRDT-based global consistency for rate limits enforced across regions."
    },
    {
      "id": "ecosystem",
      "title": "Ecosystem",
      "role": "content",
      "text": "The following libraries and frameworks provide Redis-backed rate limiting:\n\n-   **Node.js**:\n    [rate-limiter-flexible](https://github.com/animir/node-rate-limiter-flexible),\n    [express-rate-limit](https://github.com/express-rate-limit/express-rate-limit)\n    (with a Redis store)\n-   **Python**: [limits](https://limits.readthedocs.io/),\n    plus custom implementations on top of [redis-py](https://redis.readthedocs.io/)\n-   **Go**: [go-redis/redis_rate](https://github.com/go-redis/redis_rate)\n-   **API gateways**:\n    [Apache APISIX](https://apisix.apache.org/docs/apisix/plugins/limit-count/),\n    [Kong](https://docs.konghq.com/hub/kong-inc/rate-limiting/), and\n    [Envoy](https://www.envoyproxy.io/docs/envoy/latest/configuration/http/http_filters/rate_limit_filter)\n    use Redis for distributed rate limiting"
    },
    {
      "id": "code-examples-to-build-your-own-redis-rate-limiter",
      "title": "Code examples to build your own Redis rate limiter",
      "role": "example",
      "text": "The following guides show how to build a token bucket rate limiter with Redis and Lua scripts.\nEach guide includes a runnable interactive demo for each of the following client libraries:\n\n* [redis-py (Python)](https://redis.io/docs/latest/develop/use-cases/rate-limiter/redis-py)\n* [node-redis (Node.js)](https://redis.io/docs/latest/develop/use-cases/rate-limiter/nodejs)\n* [go-redis (Go)](https://redis.io/docs/latest/develop/use-cases/rate-limiter/go)\n* [Jedis (Java)](https://redis.io/docs/latest/develop/use-cases/rate-limiter/java-jedis)\n* [Lettuce (Java)](https://redis.io/docs/latest/develop/use-cases/rate-limiter/java-lettuce)\n* [StackExchange.Redis (C#)](https://redis.io/docs/latest/develop/use-cases/rate-limiter/dotnet)\n* [Predis (PHP)](https://redis.io/docs/latest/develop/use-cases/rate-limiter/php)\n* [redis-rb (Ruby)](https://redis.io/docs/latest/develop/use-cases/rate-limiter/ruby)\n* [redis-rs (Rust)](https://redis.io/docs/latest/develop/use-cases/rate-limiter/rust)"
    }
  ],
  "examples": []
}
