Works with the AI Agents you already use

    Claude CodeClaude CodeCursorCursorCodex CLICodex CLIMuseMuseDotsDots+21 more

    API Rate Limiting Redis Strategist

    1

    Implement distributed API rate limiting using atomic Redis Lua scripts and standard IETF headers.

    $15

    Secure checkout via Stripe

    Money-back guarantee

    Converts to your local currency at checkout

    Security scanned
    API Rate Limiting Redis Strategist

    API Rate Limiting Redis Strategist

    Example session with this skill installed

    I need to implement a sliding window rate limiter in Redis for my Express.js API. Use Lua scripts for atomicity and include standard IETF headers.

    • Read your context and instructions
    • Compiled the api rate limiting

    I have generated a high-performance Sliding Window Counter implementation using an atomic Redis Lua script and Express.js middleware.

    Redis Sliding Window Implementation

    // rateLimiter.js
    const Redis = require('ioredis');
    const redis = new Redis(process.env.REDIS_URL);
    
    const SLIDING_WINDOW_LUA = `
    local key = KEYS[1]
    local now = tonumber(ARGV[1])
    local window = tonumber(ARGV[2])
    local limit = tonumber(ARGV[3])
    
    redis.call('ZREMRANGEBYSCORE', key, 0, now - window)
    local current_count = redis.call('ZCARD', key)
    
    if current_count < limit then
        redis.call('ZADD', key, now, now)
        redis.call('EXPIRE', key, window / 1000)
        return {limit, limit - current_count - 1, 0}
    else
        local oldest = redis.call('ZRANGE', key, 0, 0, 'WITHSCORES')
        local retry_after = 0
        if #oldest > 0 then
            retry_after = math.max(0, math.ceil((tonumber(oldest[2]) + window - now) / 1000))
        end
        return {limit, 0, retry_after}
    end
    `;
    
    async function rateLimit(req, res, next) {
      const key = `rate_limit:${req.ip}`;
      const now = Date.now();
      const windowMs = 60000; // 1 minute
      const limit = 100;
    
      const [max, remaining, retryAfter] = await redis.eval(
        SLIDING_WINDOW_LUA, 1, key, now, windowMs, limit
      );
    
      res.setHeader('RateLimit-Limit', max);
      res.setHeader('RateLimit-Remaining', remaining);
      res.setHeader('RateLimit-Reset', Math.ceil(windowMs / 1000));
    
      if (remaining === 0 && retryAfter > 0) {
        res.setHeader('Retry-After', retryAfter);
        return res.status(429).json({ error: 'Too Many Requests' });
      }
      next();
    }
    
    module.exports = rateLimit;
    

    Next steps

    1. Add REDIS_URL to your .env file.
    2. Apply the rateLimit middleware to your sensitive routes in app.js.
    3. Verify header presence using curl -I on your local endpoint.

    Connects securely to your tools. The creator never sees your data.

    About this skill

    Managing API traffic spikes in a distributed environment often leads to race conditions and inaccurate limit tracking. This skill provides production-ready rate limiting logic using atomic Redis operations to ensure consistency across multiple service instances.

    What it does

    • Algorithm selection identifies whether Sliding Window Counter or Token Bucket best fits your specific traffic profile.
    • Atomic Lua scripting bundles Redis commands into a single roundtrip to prevent race conditions without complex locking.
    • IETF header injection implements standard RateLimit-Limit, RateLimit-Remaining, and RateLimit-Reset HTTP headers.
    • Error handling generates compliant 429 Too Many Requests responses including Retry-After logic.
    • Middleware generation outputs integration code for Node.js or Python backend stacks.

    How it works

    1. Analyze Requirements to determine if you need burst tolerance or strict accuracy.
    2. Generate Lua Scripts using commands like ZREMRANGEBYSCORE and ZCARD for high-performance set management.
    3. Configure Headers to match IETF standards for client-side rate limit awareness.
    4. Implement Middleware by wrapping your existing API routes with the generated Redis logic.

    Frameworks & tools

    This skill focuses on Redis for state management and Lua for atomicity. It provides integration code primarily for Node.js and Python backend environments.

    Why this beats prompting it yourself

    Generic prompts often produce non-atomic code that fails under high concurrency or produces inaccurate counts. This skill enforces atomic Redis operations and strictly follows IETF header standards to ensure your rate limiting is both reliable and developer-friendly.

    Use cases

    • Prevent API abuse by implementing per-user sliding window limits.
    • Manage shared resource access across a distributed microservices cluster.
    • Standardize rate limit headers for public-facing developer APIs.
    • Handle sudden traffic bursts using a burst-tolerant Token Bucket implementation.

    Known limitations

    Restricted to Redis-backed implementations. Requires a Node.js or Python environment for the middleware wrappers.

    Requires Redis. Limited to Node.js and Python middleware. Workspace restricted to active project directory.

    How to use

    1. 1

      Connect your agent to the Agensi MCP

      Copy the prompt and paste it into Claude, ChatGPT, Cursor or any agent that supports MCP. It sets up the connection for you. Manual setup

    2. 2

      Sign in to Agensi

      Your agent shows a sign-in link. Sign in and click Allow.

    3. 3

      Ask for what you need

      Your agent loads this skill and uses it on your task. It always asks before any payment.

    Reviews

    No reviews yet

    Be one of the first to try it. Every listed skill goes through the trust checks below.

    Security scanned

    Checked by our 8-point scan before listing

    Fresh listing

    Recently published to Agensi

    Money-back guarantee

    Doesn't do what its page promises? You get your money back.

    Trust & safety

    Security scan

    Security scan passed 3 days ago

    Requires

    File System Read/Write (strictly scoped to current project workspace `./`).
    Zero global installation or elevated privileges required.

    Permissions

    Read Files

    Target Use Cases: - Implement sliding window rate limiting in Redis with Lua. - Configure API rate limiting with IETF RateLimit headers. - Build a distributed rate limiter for microservices in Node.js.

    Listed3 days ago

    What's inside

    Frequently Asked Questions

    This skill eliminates race conditions in distributed environments by using atomic Redis Lua scripts, ensuring that rate limit counts remain accurate across multiple service instances even under heavy concurrent traffic.

    The skill generates production-ready Lua scripts and middleware wrappers specifically for Node.js and Python backend environments using Redis as the state store.

    You will receive optimized Redis Lua scripts for Sliding Window or Token Bucket algorithms, IETF-compliant header configurations, and the middleware integration code for your chosen language.

    Yes, it is designed for distributed systems; because it relies on a central Redis instance or cluster, all your microservices will share a consistent view of the user's current rate limit status.

    The skill includes logic to automatically inject standard IETF headers like 'RateLimit-Remaining' and 'RateLimit-Reset' into your API responses, helping your API consumers handle throttling gracefully.

    The strategist is designed to work with any modern LLM-based agent that supports code generation and architectural planning, acting as a specialized knowledge layer for high-concurrency backend design.

    New in APIs & Backend