All Projects → myntra → Golimit

myntra / Golimit

Licence: mit
Golimit is Uber ringpop based distributed and decentralized rate limiter

Programming Languages

go
31211 projects - #10 most used programming language
golang
3204 projects

Projects that are alternatives of or similar to Golimit

Nginx Lua Redis Rate Measuring
A lua library to provide distributed rate measurement using nginx + redis, you can use it to do a throttling system within many nodes.
Stars: ✭ 109 (-81.24%)
Mutual labels:  rate-limiter, distributed-systems
Copycat
A novel implementation of the Raft consensus algorithm
Stars: ✭ 551 (-5.16%)
Mutual labels:  distributed-systems
Dslabs
Distributed Systems Labs and Framework
Stars: ✭ 461 (-20.65%)
Mutual labels:  distributed-systems
Maelstrom
A workbench for writing toy implementations of distributed systems.
Stars: ✭ 493 (-15.15%)
Mutual labels:  distributed-systems
Pysyncobj
A library for replicating your python class between multiple servers, based on raft protocol
Stars: ✭ 468 (-19.45%)
Mutual labels:  distributed-systems
Awesome Distributed Systems
Awesome list of distributed systems resources
Stars: ✭ 512 (-11.88%)
Mutual labels:  distributed-systems
Hazelcast
Open-source distributed computation and storage platform
Stars: ✭ 4,662 (+702.41%)
Mutual labels:  distributed-systems
Faang
Facebook, Amazon, Apple, Netflix and Google (FAANG) Job preparation.
Stars: ✭ 557 (-4.13%)
Mutual labels:  distributed-systems
Reactivemanifesto
The Reactive Manifesto
Stars: ✭ 542 (-6.71%)
Mutual labels:  distributed-systems
Verdi
A framework for formally verifying distributed systems implementations in Coq
Stars: ✭ 496 (-14.63%)
Mutual labels:  distributed-systems
Package
Metaparticle/Package: Language Fluent Containerization and Deployment in Java, .NET and Javascript (and more coming soon)
Stars: ✭ 493 (-15.15%)
Mutual labels:  distributed-systems
Nsq
A realtime distributed messaging platform (forked from https://github.com/nsqio/nsq)
Stars: ✭ 476 (-18.07%)
Mutual labels:  distributed-systems
Cadence
Cadence is a distributed, scalable, durable, and highly available orchestration engine to execute asynchronous long-running business logic in a scalable and resilient way.
Stars: ✭ 5,522 (+850.43%)
Mutual labels:  distributed-systems
Gaia
Build powerful pipelines in any programming language.
Stars: ✭ 4,534 (+680.38%)
Mutual labels:  distributed-systems
Pachyderm
Reproducible Data Science at Scale!
Stars: ✭ 5,305 (+813.08%)
Mutual labels:  distributed-systems
Api Boot
“ ApiBoot”是为接口服务而生的,基于“ SpringBoot”完成扩展和自动配置,内部封装了一系列的开箱即用Starters。
Stars: ✭ 460 (-20.83%)
Mutual labels:  rate-limiter
Scalecube Services
ScaleCube Services is a high throughput, low latency reactive microservices library built to scale. it features: API-Gateways, service-discovery, service-load-balancing, the architecture supports plug-and-play service communication modules and features. built to provide performance and low-latency real-time stream-processing. its open and designed to accommodate changes. (no sidecar in a form of broker or any kind)
Stars: ✭ 482 (-17.04%)
Mutual labels:  distributed-systems
Iotex Core
Official implementation of IoTeX blockchain protocol in Go.
Stars: ✭ 505 (-13.08%)
Mutual labels:  distributed-systems
Neutrino
Privacy-Preserving Bitcoin Light Client
Stars: ✭ 564 (-2.93%)
Mutual labels:  distributed-systems
Git Bug
Distributed, offline-first bug tracker embedded in git, with bridges
Stars: ✭ 5,431 (+834.77%)
Mutual labels:  distributed-systems

Golimit A Distributed Rate limiter

Golimit is Uber ringpop based distributed and decentralized rate limiter. It is horizontally scalable and is based on shared nothing architecture. Every node in system is capable of handling read and writes of counters. It is designed to offer sub milliseconds latency to caller application. Recommended deployment topology is sidecar model. Every golimit node keeps local and global counter for api counter and local value is synchronized with other nodes on configurable periodic interval or at defined threshold.

Architecture

Http server provides http interface to increment counter against any arbitrary Key string. It also exposes admin api to manage global configurations.

Store encapsulates the data structure and functions to store, manage and replicate counters. Counter synchronisation is done in asynchronous way so the caller application is never blocked for cluster sync. Synchronizer module keeps aggregating counters in memory and broadcast to other nodes on periodic intervals or when the counter has crossed threshold. the interval and threshold are configurable.

StatsD Emitter pushes metrics to configured statsd server.

Block Diagram

Deployment

Suggested deployment model is to have golimit installed as sidecar. This will ensure application latency to sub milliseconds level. For Go applications golimit can be directly integrated as a module, the way of using golimit as module is explained later in document. Using as module takes away the pain of deployment and maintenance.

Block Diagram

Installation

  1. Build

    $ GOOS=linux GOARCH=amd64 go build  //Linux
    
    $ GOOS=darwin GOARCH=amd64 go build //OSX 
    
    $ GOOS=windows GOARCH=amd64 go build //Windows
    
  2. Configure

    Yml config

        clustername:  MyGolimitCluster # Cluster Name
        tchannelport: 2345 # Ringpop T Channel Port
        seed: "127.0.0.1:2345" # Seed node of cluster
        unsyncedctrlimit: 5  # Unsynced counter limit
        unsyncedtimelimit: 60000 # unsynced timeout in ms
        httpport: 8080  # Http server port
        statsdenabled: true # Enable statsd 
        statsdhostport: "metrics.xyz.com:80"  # statsd host port
        statsdsamplerate: 1 # Statsd sampling rate
        apisecret: alpha # secret key to use admin apis
        hostname: "127.0.0.1"
        unixsocketenable: true #enables unix socket,
                               #gives nearly 2x better performance in response time 
                               #when enabled tcp port config will be ignored and disabled 
        unixsocket: /tmp/golimit.sock #unix socket file location
        
    

    Note: Ensure the seed node is always reachable.

  3. Run

    $ ./golimitV3 --config=./golimitconfig.yml
    
  4. Use from Http Apis

    Param Description
    K Key a string, against this the counters are calculated
    C Count in number, numbers to increment in one api call, defaults to 1
    W Window in seconds, time window for which provided threshold is applicable
    T Threshold in number
    P PeakAveraged 0 or 1, if P=1 the provided rate limit is transposed to per second limit and then applied
    • INCR Request

      Application passes Key threshold and window and reply is block or not. This rate limiting is application driven as application has to pass all rate configuration in every call In following example second curl within 10 seconds gives back blocked =true

      $  curl -X POST "http://localhost:8080/incr?K=abc&T=1&W=10" 
      
      {"Block":false}
      
      $  curl -X POST "http://localhost:8080/incr?K=abc&T=1&W=10" 
          
      {"Block":true}
      
    • Create/Update global rate configuration, this is for rate limiting which is golimit cluster driven

      $ curl -X PUT  "http://localhost:8080/rate" -d '{"Window":60,"Limit":5,"Key":"a","PeakAveraged":false}' -H "apisecret: alpha" 
         
      {"Success":true}
      
      $ curl -X POST  "http://localhost:8080/ratelimit?K=a" 
      
      {"Block":false}
      
      # after 5 times
      # {"Block":true}
      
      
    • Ratelimit Request

       $ curl -X POST  "http://localhost:8080/ratelimit?K=a" 
       
       {"Block":false}
       
      
    • Get All defined Rate Config

      $ curl  "http://localhost:8080/rateall" 
      
      {"a":{"Window":60,"Limit":5,"PeakAveraged":false}}
      
      
    • Get a specific Rate Config

      $ curl  "http://localhost:8080/rate?K=a" 
      
      {"Window":60,"Limit":5,"PeakAveraged":false}%
      
      
    • Get Cluster Info

      $ curl  "http://localhost:8080/clusterinfo" 
      
      {"Whoami":"127.0.0.1:2345","Ready":true,"Uptime":9223372036854775807,"Members":["127.0.0.1:2345"]}   
      
      
  5. Use as Go module

    If application is in golang, golimit can be used as module directly instead of deploying as separate process.

    To install library:

    go get github.com/myntra/golimit

    package main
    import ("github.com/myntra/golimit/store")
    
    func main() {
    
        //Instantiate Store object, Use single store instance in one application
        store := store.NewStore()
    
        blocked := store.Incr("key", 1, 1000, 60, true) // Increment api
    
        if (blocked) {
            //Blocked
        }
    
        //Ensure Store is closed on program exit
        store.Close()
    }
    
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].