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
- 01
Build the basic middleware skeleton
~1.5hWrite a Rack middleware class implementing #call that passes requests through to the next app.
- 02
Implement a sliding window counter
~2.5hTrack request timestamps per client IP in memory and implement sliding-window rate limit logic.
- 03
Return proper rate-limit responses
~1.5hWhen limits are exceeded, return a 429 response with Retry-After and rate-limit headers.
- 04
Make limits configurable
~1hAllow configuring requests-per-window and window size when initializing the middleware.
- 05
Test against a sample Rack app
~2hMount 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.
Tech stack