Skip to content

sanaullahmohammed/rate-limiter

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

2 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Rate Limiter

A rate limiter is a software or hardware component used to control the rate at which certain operations or requests are allowed to occur within a system or application. It is a crucial tool for managing and regulating the flow of data, requests, or actions to prevent overuse of resources, maintain system stability, and protect against abuse or denial-of-service attacks.

Table of Contents
  1. About The Project
  2. Getting Started
  3. Usage
  4. Postman
  5. Roadmap
  6. Results
  7. Contributing
  8. License

About The Project

Built With

  • NodeJS
  • TypeScript
  • ExpressJS
  • Jest

Getting Started

This is an example of how you may give instructions on setting up your project locally. To get a local copy up and running follow these simple example steps.

Prerequisites

This is an example of how to list things you need to use the software and how to install them.

  • npm
    npm install npm@latest -g

Installation

  1. Clone the repo
    git clone https://github.com/tanmayidev/rate-limiter.git
  2. Install NPM packages
    npm install
  3. Run the project
    npm run start

Usage

Use this space to show useful examples of how a project can be used. Additional screenshots, code examples and demos work well in this space. You may also link to more resources.

  1. Endpoints:

    This service provides two endpoints:

    • /limited: This endpoint is rate-limited.
    • /unlimited: This endpoint has no rate limits.
  2. Custom Rate Limiting:

    To specify a custom rate limit and rate-limiting algorithm for a request, use the following HTTP headers:

    • origin-ipaddress (Mandatory for /limited endpoint): Set this header to specify the custom IP address for rate limiting.

    • rate-limiting-algo: Use this header to specify the rate limiting algorithm. It accepts the following values:

      0: Token Bucket
      1: Fixed Window Counter
      2: Sliding Window Log
      3: Sliding Window Counter
      
  3. Default Algorithm:

    If the rate-limiting-algo header is not specified, it defaults to the Token Bucket algorithm.

Postman

Postman configurations to stress-test the apis

Pre-Request-Script

The following script randomly picks ip-addresses from the given list (ipAddrs). Please see Dynamic-variables and Using-variables.

function pickIpAddr() {
  const ipAddrs = ['143.33.72.232', '42.33.106.86', '164.78.11.195', '216.217.171.55', '181.81.57.111'];
  const idx = _.random(0, 4);
  return ipAddrs[idx];
}

pm.variables.set('custom_ip', pickIpAddr());

Http-Headers

  1. The origin-ipaddress is assigned a dynamic-variable ({{custom_ip}}), which is evaluated in the Pre-Request Script.
  2. The rate-limiting-algo http-header specifies appropriate algorithm to be applied. Look at Enum, Step-2 in usage
origin-ipaddress:   {{custom_ip}}
rate-limiting-algo: 0

Roadmap

  • Token Bucket
  • Fixed Window Counter
  • Sliding Window Log
  • Sliding Window Counter
    • Implement the algorithm
    • Integrate with Load-Balancer in a horizontally scaled architecture.
  • Write unit-tests

See the open issues for a full list of proposed features (and known issues).

Results

Contributing

Contributions are what make the open source community such an amazing place to learn, inspire, and create. Any contributions you make are greatly appreciated.

If you have a suggestion that would make this better, please fork the repo and create a pull request. You can also simply open an issue with the tag "enhancement". Don't forget to give the project a star! Thanks again!

  1. Fork the Project
  2. Create your Feature Branch (git checkout -b feature/AmazingFeature)
  3. Commit your Changes (git commit -m 'Add some AmazingFeature')
  4. Push to the Branch (git push origin feature/AmazingFeature)
  5. Open a Pull Request

License

Distributed under the ISC License. MIT License

About

Rate limiter prevents the same IP address from making too many requests preventing brute force attacks

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors