TLDR: Sliding Window Rate Limiting - Design and Implementation
Date: 2020-04-05 Source: https://arpitbhayani.me/blogs/sliding-window-ratelimiter
Overview
A rate limiter restricts the intended or unintended excessive usage of a system by regulating the number of requests made to/from it by discarding the surplus ones.
Key Points
- A rate limiter restricts the intended or unintended excessive usage of a system by regulating the number of requests made to/from it by discarding the surplus ones.
- Visualizing sliding window: Every time we get a request, we make a decision to either serve it or not; hence we check the number_of_requests made in last time_window_sec seconds.
- The pseudocode: The core of the algorithm could be summarized in the following Python pseudocode.
- Components of the Rate limiter: The Rate limiter has the following components
- Deciding the datastores: Picking the right data store for the use case is extremely important.