Live data from Hacker News

An Alternative Approach to Rate Limiting

medium.com

31–40 of 73 posts

Re: An Alternative Approach to Rate Limiting

#31
post #26

In response, we implemented a shadow ban: On the surface, the attackers continued to receive a 200 HTTP response code, but behind the scenes we simply stopped sending document invitations after they exceeded the rate limit. And right there they broke the service for legitimate users. Totally unacceptable collateral damage IMHO.

The problem with rate limiting is to distinguish a normal user from a spammer. A normal user can send more requests than usual sometimes. If a normal user gets rate-limited by mistake, you are going to get lots of upset users.

Re: An Alternative Approach to Rate Limiting

#32
post #26

In response, we implemented a shadow ban: On the surface, the attackers continued to receive a 200 HTTP response code, but behind the scenes we simply stopped sending document invitations after they exceeded the rate limit. And right there they broke the service for legitimate users. Totally unacceptable collateral damage IMHO.

Wow, that's really bad. I get shivers at the thought of trying to troubleshoot that as a client.

Re: An Alternative Approach to Rate Limiting

#33
post #26

In response, we implemented a shadow ban: On the surface, the attackers continued to receive a 200 HTTP response code, but behind the scenes we simply stopped sending document invitations after they exceeded the rate limit. And right there they broke the service for legitimate users. Totally unacceptable collateral damage IMHO.

The problem with rate limiting is to distinguish a normal user from a spammer. A normal user can send more requests than usual sometimes. If a normal user gets rate-limited by mistake, you are going to get lots of upset users.

Rate-limiting is also used to protect against legitimate users who have made mistakes in config (or are poorly-skilled), not just spammers. It's much better to let them know why things aren't working than actively lie about it.

Re: An Alternative Approach to Rate Limiting

#35
post #32
post #26

In response, we implemented a shadow ban: On the surface, the attackers continued to receive a 200 HTTP response code, but behind the scenes we simply stopped sending document invitations after they exceeded the rate limit. And right there they broke the service for legitimate users. Totally unacceptable collateral damage IMHO.

Wow, that's really bad. I get shivers at the thought of trying to troubleshoot that as a client.

I've had this happen before. Found out I was locked out from an email I read later while the login form happily rejected all my attempts.

Re: An Alternative Approach to Rate Limiting

#36
You know you can implement a token bucket that doesn't share state between your API servers, in about 10 lines of code, using just a in memory map.

Your incoming requests should be balanced across all of the servers so you just derive the allowed throughput and divide by the number front ends....

Re: An Alternative Approach to Rate Limiting

#37
post #24
post #17

Earlier quoted context omitted.

This is why I've suggested, and used, fair queuing for rate limiting. Any source can make lots of requests, but they queue up by IP address. (In practice, you have queues organized by hashed IP address, which you service round-robin. That's how routers do fair queuing.) If one queue gets very long, then you start sending 429 errors for new adds to that queue. Otherwise, the requests from the heavy load source just ta…

Neat idea, but if you hash the same as the spammer?

If you're worried about that, randomize the hash key every day or so. The queuing will be suboptimal for about a minute.

Re: An Alternative Approach to Rate Limiting

#38

You know you can implement a token bucket that doesn't share state between your API servers, in about 10 lines of code, using just a in memory map. Your incoming requests should be balanced across all of the servers so you just derive the allowed throughput and divide by the number front ends....

You have to send all the traffic from one client to one server then right? Seems not without heavy drawbacks.

Otherwise you can easily get them to hit their limit super early with bad luck.

Re: An Alternative Approach to Rate Limiting

#39

You know you can implement a token bucket that doesn't share state between your API servers, in about 10 lines of code, using just a in memory map. Your incoming requests should be balanced across all of the servers so you just derive the allowed throughput and divide by the number front ends....

You have to send all the traffic from one client to one server then right? Seems not without heavy drawbacks. Otherwise you can easily get them to hit their limit super early with bad luck.

No, you evenly round robin all traffic to all servers.

Each server contains a map of tokens per per client filling at a fixed interval.

That interval is calculated by taking the total global token refresh rate and dividing it by the number of servers.

The end result is exactly the same but, now you are stateless and have eliminated the bottleneck of a central token bucket.

Re: An Alternative Approach to Rate Limiting

#40
post #24
post #17

Earlier quoted context omitted.

This is why I've suggested, and used, fair queuing for rate limiting. Any source can make lots of requests, but they queue up by IP address. (In practice, you have queues organized by hashed IP address, which you service round-robin. That's how routers do fair queuing.) If one queue gets very long, then you start sending 429 errors for new adds to that queue. Otherwise, the requests from the heavy load source just ta…

Neat idea, but if you hash the same as the spammer?

The chances are incredibly slim, and even if it does it's only one user.
Post reply on HN