Coder Social home page Coder Social logo

redis-rate-limiter's Introduction

RATE_LIMIT_POC

Notes

  • This POC is based on github.com/go-redis/redis_rate/v9 package for rate limiting, which internally implements Leaky Bucket rate algorithm.

  • This package relies on a Redis instance for persisting rate limiting specific information. This POC assumes that there is a Redis instance running on your machine at PORT=6379.

  • This POC demonstrates both middleware based and standalone function based implementations for rate limiting.

  • There are 3 endpoints being served from the server:

Endpoint 1

  • POST /auth - This POST endpoint is a simulation of an authentication endpoint where user will provide their Identification Type(passport/nationalid/taxid) and the value of that identification in the request body as JSON.

      Success response also writes a cookie on the client named - `session_id` which has a `MaxAge` of 60 secs.
    

Request

    {
        "type": "passport",
        "value": "XXXXXXX"
    }

Response 1 - Success

Authentication successful

Response 1 - Exceeded Rate Limit quota

Too Many Requests

Endpoint 2

  • GET /otp - This GET endpoint is a simulation of when we identified customer in Nana database and now we need to send an OTP for them to validate.
    This API requires session_id cookie to be present on client, hence /auth endpoint needs to be invoked first

Response 1 - Success 200 OK

Here is your new OTP: <new/existing otp>

Response 2 - 400 Bad Request

no session_id cookie received

Response 3 - 429 Too many requests

Too Many Requests

redis-rate-limiter's People

Contributors

ilivestrong 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.