Search code examples
rate-limiting

What is the difference between rate limiting and back pressure?


What is the difference between rate limiting and back pressure? Is it mainly that rate limiting is the client slowing down on its own and back pressure is the service dropping requests to slow down?


Solution

  • Rate limiting detects that some action is happening too much in some time frame, and prevents it from happening again until that time frame is over.

    For instance, say I have an application that sends an email every time an error is generated. The application talks to a queue that gets polled multiple times a second. So if there is a misconfiguration of the queue then the application can generate thousands of emails in an hour. Adding rate limiting can keep track of the number of error emails sent within a time frame and stop sending emails when the count gets high enough. Or the application could back off polling the queue for some time interval.

    Back pressure means that the system refuses to take more work. Unlike rate limiting there is no set time where the application resumes taking on work, it depends on the application detecting it has capacity.

    If I have an application that receives work through a fixed size blocking queue, then, once the queue fills up, anything that tries to put a new entry in the queue will wait until the queue can make room for it. That way the application doesn’t take more work than it can manage, causing it to run out of memory or otherwise getting into a bad state.