Senior
What is Rate Limiting? What algorithms exist?
sobes.tech AI
Answer from AI
Rate Limiting is a mechanism to restrict the number of requests to a service within a certain period of time to protect the system from overload and abuse.
Main Rate Limiting algorithms:
- Token Bucket — tokens accumulate in a bucket at a fixed rate; a token is required to perform a request. If there are no tokens, the request is rejected.
- Leaky Bucket — requests are queued at a fixed processing rate, excess requests 'leak' out and are discarded.
- Fixed Window — counts the number of requests within a fixed time window (e.g., 1 minute). If the limit is exceeded, requests are blocked.
- Sliding Window — a more precise version of Fixed Window, considering a sliding time window for counting requests.
In Go, the golang.org/x/time/rate package is often used to implement Rate Limiting, which implements the Token Bucket.