TL;DR
Rate limiting with an in-memory counter stops working the moment you run more than one instance. Each instance counts on its own, so three instances allow three times the limit.
Moving the counter into Redis isn't enough on its own. A read-then-write version let 1,200 of 1,200 requests through a limit of 100 in my test.
The fix: one Lua script that reads, refills and takes a token in a single atomic step, using Redis's clock. Same test: exactly 100 of 1,200 .
When Redis goes down, a circuit breaker switches each instance to a smaller local limit instead of letting everything through.
About 1 ms per decision at the median. Code: github.com/Rimaz17/RateGuard .
When an application runs on a single server, rate limiting is easy. You keep a counter in memory, add one for each request, and refuse requests once the counter passes the limit.
The trouble starts when you add a second server. I wanted to understand that problem properly, so I built RateGuard : a standalone rate-limiting service in Go.…