RubyadvanceddevopsAI generated

Custom Rack Middleware Rate Limiter

Build a standalone Rack middleware that enforces per-IP request rate limits using a sliding window algorithm, configurable for any Rack-based Ruby app. Learners practice Rack middleware architecture, in-memory data structures for rate tracking, and writing framework-agnostic Ruby libraries.

Estimate
~8.5h
Steps
5
Completed by
0
Proposed by
codeseed.app

Rack

Project roadmap

  1. 01

    Build the basic middleware skeleton

    ~1.5h

    Write a Rack middleware class implementing #call that passes requests through to the next app.

  2. 02

    Implement a sliding window counter

    ~2.5h

    Track request timestamps per client IP in memory and implement sliding-window rate limit logic.

  3. 03

    Return proper rate-limit responses

    ~1.5h

    When limits are exceeded, return a 429 response with Retry-After and rate-limit headers.

  4. 04

    Make limits configurable

    ~1h

    Allow configuring requests-per-window and window size when initializing the middleware.

  5. 05

    Test against a sample Rack app

    ~2h

    Mount the middleware in a small Sinatra or Rack app and write tests simulating burst traffic.

Resources

Ready to build this?

Get a GitHub repo and start building. Your AI reviewer checks each step as you go.

~8.5h · 5 steps

Tech stack

Rack