Skip to content

FarajGopher/Rate-limiting

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

4 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Rate Limiting

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.


Algorithms Implemented

  1. Fixed Window
  2. Sliding Logs
  3. Leaky Bucket
  4. Sliding Window
  5. Token Bucket

Overview of Algorithms

1. Fixed Window

  • 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

2. Sliding Logs

  • 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

3. Leaky Bucket

  • 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

4. Sliding Window

  • 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

5. Token Bucket

  • 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

Prerequisites

  • Go 1.20+
  • Redis (local or cloud instance)

Getting Started

  1. Clone the repository:
git clone https://github.com/FarajGopher/Rate-limiting.git
cd rate-limiting

About

Rate limiting multiple algorithm using redis

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages