DEV Community

Shayan M Hussain
Shayan M Hussain

Posted on

I built a rate limiter that's 9x faster than rate-limiter-flexible - benchmarks included

The Problem

With express-rate-limit, tiered limits require:

  • Creating 3 separate limiter instances
  • Writing manual routing logic
  • 25 lines of code minimum

The Solution

app.use(hitlimit({
  tiers: {
    free: { limit: 100, window: '1h' },
    pro: { limit: 5000, window: '1h' },
    enterprise: { limit: Infinity }
  },
  tier: (req) => req.user?.plan || 'free'
}))
Enter fullscreen mode Exit fullscreen mode

8 lines. Done.

Benchmarks

I ran 1.5M iterations per scenario. Raw store operations to keep it fair:

Library ops/sec
hitlimit 9.56M 🏆
express-rate-limit 6.32M
rate-limiter-flexible 1.01M

Benchmark script is in the repo if you want to verify.

Other features:

  • Human-readable time windows ('15m' instead of 900000)
  • 7KB bundle (vs 45KB for rate-limiter-flexible)
  • Memory, SQLite, and Redis stores
  • Per-request error handling (fail-open vs fail-closed)

Links:

It's brand new, so feedback is super welcome. What features would make this useful for your projects?


Top comments (0)