Post-GA blog: Skip the Plugin — Building a Rate-Limited API in Wheels 4.0 #2698
bpamiri
announced in
Announcements
Replies: 0 comments
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
-
Now that 4.0 is out, the post-GA blog series shifts from "what shipped" to "how do you actually use it?" First in the series is the middleware stack — specifically rate limiting, which used to be the most common "I need a plugin for this" request.
Read: https://blog.wheels.dev/posts/skip-the-plugin-rate-limited-api
The post is a guided tour of
wheels.middleware.RateLimiter,Cors, andSecurityHeaderscomposed via the new pipeline. It walks through:fixedWindow(default, cheap),slidingWindow(accurate),tokenBucket(allows bursts). Picked by behavior, not by name.keyFunctionhero example — a small closure that buckets authenticated traffic perX-Api-Keyand falls back to IP for anonymous. Same office NAT, different buckets for different keys.trustProxyandproxyStrategy— why it's off by default (X-Forwarded-For spoofing), why"last"is right behind nginx withproxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;, and where Cloudflare'sCF-Connecting-IPfits.storage="database"for multi-instance, and the auto-createdwheels_rate_limitstable.failOpenvs fail-closed — secure default, when to override.Side note: a small framework fix surfaced while writing this
While probing edge cases for the post,
windowSeconds = 0turned out to leak a generic CFMLYou cannot divide by zeroout of thefixedWindowandtokenBucketstrategy math — accurate but useless for debugging. That's #2693, fixed in the same week the article landed. The constructor now refuseswindowSeconds <= 0and negativemaxRequestsat init time and throwsWheels.RateLimiter.InvalidConfigurationwith a message naming the bad parameter, matching the pattern already used forstrategy,storage, andproxyStrategy.maxRequests = 0is still legal — it's the kill-switch idiom for "block everything," useful in incident response.What's next in the post-GA series
The remaining four titles from the second batch:
wheels deployFeedback on the rate-limiting post — what worked, what didn't, what you'd want covered next — welcome in this thread.
Beta Was this translation helpful? Give feedback.
All reactions