All Projects → coveooss → spillway

coveooss / spillway

Licence: MIT License
A simple, distributed and flexible rate limiter

Programming Languages

java
68154 projects - #9 most used programming language

Projects that are alternatives of or similar to spillway

polaris-go
Lightweight Go SDK as Data Plane of Proxyless Service Governance Solution
Stars: ✭ 35 (+20.69%)
Mutual labels:  rate-limit
polaris
Service Governance Center for Distributed and Microservice Architecture
Stars: ✭ 1,062 (+3562.07%)
Mutual labels:  rate-limit
fastapi-framework
A FastAPI Framework for things like Database, Redis, Logging, JWT Authentication, Rate Limits and Sessions
Stars: ✭ 26 (-10.34%)
Mutual labels:  rate-limit
freebind
IPv4 and IPv6 address rate limiting evasion tool
Stars: ✭ 88 (+203.45%)
Mutual labels:  rate-limit
FireflySoft.RateLimit
It is a rate limiting library based on .Net standard.
Stars: ✭ 76 (+162.07%)
Mutual labels:  rate-limit
adaptive throttler
manages multiple throttlers with ability to ramp up and down
Stars: ✭ 31 (+6.9%)
Mutual labels:  rate-limit
polaris-cpp
Lightweight C/C++ SDK used as Proxyless Service Governance Solution
Stars: ✭ 14 (-51.72%)
Mutual labels:  rate-limit
nestjs-throttler-storage-redis
Redis storage provider for the nestjs-throttler package.
Stars: ✭ 56 (+93.1%)
Mutual labels:  rate-limit
polaris-java
Lightweight Java SDK used as Proxyless Service Governance Solution
Stars: ✭ 84 (+189.66%)
Mutual labels:  rate-limit
gentle-force
Brute-force, error and request rate limiting
Stars: ✭ 45 (+55.17%)
Mutual labels:  rate-limit
rate-limit
用于限流的令牌桶算法,漏桶算法(Python实现)
Stars: ✭ 104 (+258.62%)
Mutual labels:  rate-limit

Spillway

Build Status license Maven Central

A distributed throttling solution

Spillway is an easy to use solution to add distributed throttling at the software level in your public API. This is particularly useful if multiple services are running in different JVMs. It is also possible to quickly to react when throttling happens with our built-in call-back mechanism.

Storage backend currently supported:

  • In memory (for usage within the same JVM)
  • Redis

All external storage can be (and should be) wrapped in our asynchronous storage to avoid slowing down/stopping queries if external problems occurs with the external storage.

Getting Started

Add Spillway to your project pom

<dependency>
    <groupId>com.coveo</groupId>
    <artifactId>spillway</artifactId>
    <version>2.0.0</version>
</dependency>

Documentation

The java documentation is available here: https://coveooss.github.io/spillway/

Usage

Sample 1
    LimitUsageStorage storage = new AsyncLimitUsageStorage(new RedisStorage("localhost"));
    SpillwayFactory spillwayFactory = new SpillwayFactory(storage);

    Limit<String> myLimit = LimitBuilder.of("myLimit").to(2).per(Duration.ofMinutes(1)).build();
    Spillway<String> spillway = spillwayFactory.enforce("myResource", myLimit);
    
    spillway.call("myLimit"); // nothing happens
    spillway.call("myLimit"); // nothing happens
    spillway.call("myLimit"); // throws SpillwayLimitExceededException
Sample 2
    LimitUsageStorage storage = new InMemoryStorage();
    SpillwayFactory spillwayFactory = new SpillwayFactory(storage);

    Limit<User> userLimit = LimitBuilder.of("perUser", User::getName).to(3).per(Duration.ofHours(1)).build();
    Limit<User> ipLimit = LimitBuilder.of("perIp", User::getIp).to(3).per(Duration.ofHours(1)).withExceededCallback(myCallback).build();
    Spillway<User> spillway = spillwayFactory.enforce("myResource", userLimit, ipLimit);

    User john = new User("john", "127.0.0.1");
    User gina = new User("gina", "127.0.0.1");

    spillway.tryCall(john); // true
    spillway.tryCall(gina); // true
    spillway.tryCall(john); // true
    spillway.tryCall(gina); // false, perIp limit exceeded.
Sample 3
    LimitUsageStorage storage = new InMemoryStorage();
    SpillwayFactory spillwayFactory = new SpillwayFactory(storage);
    
    LimitOverride override = LimitOverrideBuilder.of("john").to(10).per(Duration.ofHours(1)).build();
    Limit<String> userLimit = LimitBuilder.of("perUser").to(30).per(Duration.ofHours(1)).withLimitOverride(override).build();
    Spillway<User> spillway = spillwayFactory.enforce("myResource", userLimit);

    spillway.tryCall("john", 11); // false
    spillway.tryCall("gina", 20); // true

External Resources

cirrus-up-cloud wrote a nice blog post about using Spillway on AWS with Elasticache.

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].