Giter Club home page Giter Club logo

ratelimit-framework's Introduction

Ratelimit-framework

A framework that can throttle client requests in distributed system. Ratelimiting can be applied across method, apis for a particular company. This framework uses centralized Memcached to keep track of API hits.

Steps to Use

  1. Import module ratelimit in your project.

<dependency>
	<artifactId>ratelimit</artifactId>
	<groupId>com.phonepe</groupId>
	<version>0.0.1-SNAPSHOT</version>
</dependency>

  1. Ensure the package com.phonepe is in your component scan path

  2. Place memcache.properties file in your classpath and set memcache.servers.ip as the ip:port of memcache nodes.

  3. Create RateLimit object and pass it to IRateLimitService.addRateLimit(String company, RateLimit rateLimit) method;

#Example RateLimit Object

RateLimit rateLimit = new RateLimit();

String company = "E-COM";

Limit limit = new Limit();

limit.getDurationMap().put(TimeUnit.HOUR, 100);
limit.getDurationMap().put(TimeUnit.WEEK, 200);
limit.getDurationMap().put(TimeUnit.MONTH, 10000);

rateLimit.setClientLimit(limit);

Limit limit2 = new Limit();

limit2.getDurationMap().put(TimeUnit.SECOND, 10);
limit2.getDurationMap().put(TimeUnit.MINUTE, 20);
limit2.getDurationMap().put(TimeUnit.WEEK, 700);

rateLimit.getLimits().put(company + "_GET", limit2);

rateLimit.getLimits().put(company + "_/pay", limit2);

Limit limit3 = new Limit();

limit3.getDurationMap().put(TimeUnit.SECOND, 20);
limit3.getDurationMap().put(TimeUnit.HOUR, 60);
limit3.getDurationMap().put(TimeUnit.WEEK, 900);
limit3.getDurationMap().put(TimeUnit.MONTH, 1000);

rateLimit.getLimits().put(company + "_POST", limit3);

rateLimit.getLimits().put(company + "_/status", limit3);

ratelimit-framework's People

Contributors

mayank1808 avatar

Stargazers

Ronak Kothari avatar

Watchers

James Cloos avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.