Coder Social home page Coder Social logo

redisratelimiter's Introduction

Redis Rate Limiter

A service which ensures that events occur only once in a period of time (event-duration).

Modes

Only Once

A typical sliding window limiter, allowing only the first of duplicated events during the event-duration.

Example Event Duration: 3

Times and Events: {1, ๐ŸŽ}, {2, ๐ŸŒฎ}, {3, ๐ŸŒฎ}, {4, ๐ŸŒฎ}, {7, ๐ŸŒฎ}

Allowed: {1, ๐ŸŽ}, {2, ๐ŸŒฎ}, {7, ๐ŸŒฎ}

Strictly Once

A sliding window limiter, where if duplicate events occur during the event-duration, the later event(s) are rejected and the conflicting earlier event is invalidated. In short, at least event-duration time should separate events, otherwise no events are valid.

Example Event Duration: 3

Times and Events: {1, ๐ŸŽ}, {2, ๐ŸŒฎ}, {3, ๐ŸŒฎ}, {4, ๐ŸŒฎ}, {7, ๐ŸŒฎ}

Allowed: {1, ๐ŸŽ}, {7, ๐ŸŒฎ}

Event Lifecycle

  • Submitted - Potentially publishable at the time of receipt. An event will not be submitted if it conflicts with another, previously submitted event. This is the entry point into the event lifecycle.
  • Invalidated - A submitted event is invalidated when a subsequently received event creates a conflict. This is a terminal state transition, an invalidated event can never be published.
  • Published - No rate limit rules were violated, for a submitted event, throughout the event duration. This is a terminal state transition, a published event cannot be invalidated.

Synchronization

Event status updates are pushed using STOMP over Websocket. Snapshots of incubating events (events submitted but not yet published) are periodically pushed. Combined, these allow real time synchronization with other services.

All status updates and snapshots are sent with a scalar clock. It is guaranteed that clock values are unique and an event with a lesser clock value happened-before an event with a greater clock value. The state of incubating events can therefore be modeled. A parallel can be drawn to video compression: snapshots can be considered key-frames and status updates, delta-frames.

The synchronization is not partition tolerant.

Build & Run

Requirements: Docker, Docker compose and Java 19 (uses preview features)

Start RateLimiter and Redis: gradle bootRun

Stop Redis: gradle stopRedis

redisratelimiter's People

Contributors

ericghara avatar

Watchers

Kostas Georgiou avatar  avatar

redisratelimiter's Issues

Add Conditional Delete to EventMapService

A conditional delete that deletes events older than a certain timestamp would be useful for cleaning up the event map to remove old/expired events.

The EXPIRE command of Redis should not be used as in this way events could expire without being handled prior to expiration.

Add a service to expire old events

Events in the EventMap are not cleared after expiration which could lead to high resource utilization over time. The EventQueue (see: #7) provides an ideal data structure to poll for expired events.

A service should be developed to expire old events by polling them from the EventQueue and removing them from the EventMap.

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.