A collection of rate limiting algorithms implemented in Go using Redis as the backend store.
These algorithms help control the number of requests a user or client can make in a given time window.
- Fixed Window
- Sliding Logs
- Leaky Bucket
- Sliding Window
- Token Bucket
- Description: Counts requests per fixed time interval.
- Pros:
- Memory efficient
- Easy to implement
- Resets quota at the end of a window
- Cons:
- Burst traffic at window edges may exceed quota
- Not smooth for high-frequency requests
- Description: Stores timestamps of requests to enforce limits over a rolling window.
- Pros: Accurate, supports sliding window rate limiting
- Cons: High memory usage due to storing logs
- Description: Requests are processed at a fixed rate; excess requests queue or leak out.
- Pros: Smooths traffic, simple concept
- Cons: Can delay requests, requires queue management
- Description: Combines Fixed Window and Sliding Logs to allow smoother rate limiting
- Pros: More accurate than Fixed Window, supports bursts
- Cons: Slightly more complex than Fixed Window
- Description: Each user has a bucket of tokens; each request consumes one token. Tokens refill at a fixed rate.
- Pros:
- Supports bursts
- Smooths traffic
- Memory efficient
- Cons:
- Slightly more complex than Fixed Window
- Token refill timing must be handled carefully
- Go 1.20+
- Redis (local or cloud instance)
- Clone the repository:
git clone https://github.com/FarajGopher/Rate-limiting.git
cd rate-limiting