{"id":13526358,"url":"https://github.com/mennanov/limiters","last_synced_at":"2026-04-01T19:05:54.450Z","repository":{"id":40514361,"uuid":"204994237","full_name":"mennanov/limiters","owner":"mennanov","description":"Golang rate limiters for distributed applications","archived":false,"fork":false,"pushed_at":"2025-12-05T19:36:35.000Z","size":422,"stargazers_count":604,"open_issues_count":0,"forks_count":59,"subscribers_count":6,"default_branch":"master","last_synced_at":"2025-12-09T05:36:10.973Z","etag":null,"topics":["concurrent-limiter","consul","etcd","fixed-window","golang","grpc","leaky-bucket","rate-limiting","redis","sliding-windows","token-bucket","zookeeper"],"latest_commit_sha":null,"homepage":"https://godoc.org/github.com/mennanov/limiters","language":"Go","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/mennanov.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null,"zenodo":null,"notice":null,"maintainers":null,"copyright":null,"agents":null,"dco":null,"cla":null}},"created_at":"2019-08-28T18:09:54.000Z","updated_at":"2025-12-07T14:46:21.000Z","dependencies_parsed_at":"2022-06-27T17:14:11.287Z","dependency_job_id":"38a175fd-59be-4afd-a386-5b7575bf961a","html_url":"https://github.com/mennanov/limiters","commit_stats":null,"previous_names":[],"tags_count":38,"template":false,"template_full_name":null,"purl":"pkg:github/mennanov/limiters","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mennanov%2Flimiters","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mennanov%2Flimiters/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mennanov%2Flimiters/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mennanov%2Flimiters/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/mennanov","download_url":"https://codeload.github.com/mennanov/limiters/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mennanov%2Flimiters/sbom","scorecard":{"id":636565,"data":{"date":"2025-08-11","repo":{"name":"github.com/mennanov/limiters","commit":"75bf9f7d8d6411530dd533566f0e4d98ddab9991"},"scorecard":{"version":"v5.2.1-40-gf6ed084d","commit":"f6ed084d17c9236477efd66e5b258b9d4cc7b389"},"score":5.3,"checks":[{"name":"Code-Review","score":8,"reason":"Found 13/16 approved changesets -- score normalized to 8","details":null,"documentation":{"short":"Determines if the project requires human code review before pull requests (aka merge requests) are merged.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#code-review"}},{"name":"Dangerous-Workflow","score":10,"reason":"no dangerous workflow patterns detected","details":null,"documentation":{"short":"Determines if the project's GitHub Action workflows avoid dangerous patterns.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#dangerous-workflow"}},{"name":"Maintained","score":7,"reason":"9 commit(s) and 0 issue activity found in the last 90 days -- score normalized to 7","details":null,"documentation":{"short":"Determines if the project is \"actively maintained\".","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#maintained"}},{"name":"Packaging","score":-1,"reason":"packaging workflow not detected","details":["Warn: no GitHub/GitLab publishing workflow detected."],"documentation":{"short":"Determines if the project is published as a package that others can easily download, install, easily update, and uninstall.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#packaging"}},{"name":"Binary-Artifacts","score":10,"reason":"no binaries found in the repo","details":null,"documentation":{"short":"Determines if the project has generated executable (binary) artifacts in the source repository.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#binary-artifacts"}},{"name":"Token-Permissions","score":0,"reason":"detected GitHub workflow tokens with excessive permissions","details":["Info: topLevel 'contents' permission set to 'read': .github/workflows/golangci-lint.yml:10","Warn: no topLevel permission defined: .github/workflows/staticcheck.yml:1","Warn: no topLevel permission defined: .github/workflows/tests.yml:1","Warn: no topLevel permission defined: .github/workflows/vet.yml:1","Info: no jobLevel write permissions found"],"documentation":{"short":"Determines if the project's workflows follow the principle of least privilege.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#token-permissions"}},{"name":"Pinned-Dependencies","score":0,"reason":"dependency not pinned by hash detected -- score normalized to 0","details":["Warn: GitHub-owned GitHubAction not pinned by hash: .github/workflows/golangci-lint.yml:19: update your workflow using https://app.stepsecurity.io/secureworkflow/mennanov/limiters/golangci-lint.yml/master?enable=pin","Warn: GitHub-owned GitHubAction not pinned by hash: .github/workflows/golangci-lint.yml:20: update your workflow using https://app.stepsecurity.io/secureworkflow/mennanov/limiters/golangci-lint.yml/master?enable=pin","Warn: third-party GitHubAction not pinned by hash: .github/workflows/golangci-lint.yml:24: update your workflow using https://app.stepsecurity.io/secureworkflow/mennanov/limiters/golangci-lint.yml/master?enable=pin","Warn: GitHub-owned GitHubAction not pinned by hash: .github/workflows/staticcheck.yml:16: update your workflow using https://app.stepsecurity.io/secureworkflow/mennanov/limiters/staticcheck.yml/master?enable=pin","Warn: third-party GitHubAction not pinned by hash: .github/workflows/staticcheck.yml:17: update your workflow using https://app.stepsecurity.io/secureworkflow/mennanov/limiters/staticcheck.yml/master?enable=pin","Warn: GitHub-owned GitHubAction not pinned by hash: .github/workflows/tests.yml:68: update your workflow using https://app.stepsecurity.io/secureworkflow/mennanov/limiters/tests.yml/master?enable=pin","Warn: GitHub-owned GitHubAction not pinned by hash: .github/workflows/tests.yml:70: update your workflow using https://app.stepsecurity.io/secureworkflow/mennanov/limiters/tests.yml/master?enable=pin","Warn: third-party GitHubAction not pinned by hash: .github/workflows/tests.yml:74: update your workflow using https://app.stepsecurity.io/secureworkflow/mennanov/limiters/tests.yml/master?enable=pin","Warn: third-party GitHubAction not pinned by hash: .github/workflows/tests.yml:89: update your workflow using https://app.stepsecurity.io/secureworkflow/mennanov/limiters/tests.yml/master?enable=pin","Warn: GitHub-owned GitHubAction not pinned by hash: .github/workflows/vet.yml:16: update your workflow using https://app.stepsecurity.io/secureworkflow/mennanov/limiters/vet.yml/master?enable=pin","Warn: GitHub-owned GitHubAction not pinned by hash: .github/workflows/vet.yml:18: update your workflow using https://app.stepsecurity.io/secureworkflow/mennanov/limiters/vet.yml/master?enable=pin","Info:   0 out of   7 GitHub-owned GitHubAction dependencies pinned","Info:   0 out of   4 third-party GitHubAction dependencies pinned"],"documentation":{"short":"Determines if the project has declared and pinned the dependencies of its build process.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#pinned-dependencies"}},{"name":"CII-Best-Practices","score":0,"reason":"no effort to earn an OpenSSF best practices badge detected","details":null,"documentation":{"short":"Determines if the project has an OpenSSF (formerly CII) Best Practices Badge.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#cii-best-practices"}},{"name":"Security-Policy","score":0,"reason":"security policy file not detected","details":["Warn: no security policy file detected","Warn: no security file to analyze","Warn: no security file to analyze","Warn: no security file to analyze"],"documentation":{"short":"Determines if the project has published a security policy.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#security-policy"}},{"name":"Fuzzing","score":0,"reason":"project is not fuzzed","details":["Warn: no fuzzer integrations found"],"documentation":{"short":"Determines if the project uses fuzzing.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#fuzzing"}},{"name":"License","score":10,"reason":"license file detected","details":["Info: project has a license file: LICENSE:0","Info: FSF or OSI recognized license: MIT License: LICENSE:0"],"documentation":{"short":"Determines if the project has defined a license.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#license"}},{"name":"Signed-Releases","score":-1,"reason":"no releases found","details":null,"documentation":{"short":"Determines if the project cryptographically signs release artifacts.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#signed-releases"}},{"name":"Branch-Protection","score":-1,"reason":"internal error: error during branchesHandler.setup: internal error: githubv4.Query: Resource not accessible by integration","details":null,"documentation":{"short":"Determines if the default and release branches are protected with GitHub's branch protection settings.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#branch-protection"}},{"name":"Vulnerabilities","score":10,"reason":"0 existing vulnerabilities detected","details":null,"documentation":{"short":"Determines if the project has open, known unfixed vulnerabilities.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#vulnerabilities"}},{"name":"SAST","score":0,"reason":"SAST tool is not run on all commits -- score normalized to 0","details":["Warn: 0 commits out of 27 are checked with a SAST tool"],"documentation":{"short":"Determines if the project uses static code analysis.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#sast"}}]},"last_synced_at":"2025-08-21T09:20:46.413Z","repository_id":40514361,"created_at":"2025-08-21T09:20:46.413Z","updated_at":"2025-08-21T09:20:46.413Z"},"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":28693324,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-01-23T11:01:27.039Z","status":"ssl_error","status_checked_at":"2026-01-23T11:00:26.909Z","response_time":59,"last_error":"SSL_connect returned=1 errno=0 peeraddr=140.82.121.6:443 state=error: unexpected eof while reading","robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":false,"can_crawl_api":true,"host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["concurrent-limiter","consul","etcd","fixed-window","golang","grpc","leaky-bucket","rate-limiting","redis","sliding-windows","token-bucket","zookeeper"],"created_at":"2024-08-01T06:01:28.495Z","updated_at":"2026-01-23T13:28:46.998Z","avatar_url":"https://github.com/mennanov.png","language":"Go","funding_links":[],"categories":["工具库`可以提升效率的通用代码库和工具`","Go","Utilities","公用事业公司","工具库","Utility"],"sub_categories":["查询语","Utility/Miscellaneous","实用程序/Miscellaneous","HTTP Clients","Fail injection"],"readme":"# Distributed rate limiters for Golang \n[![Build Status](https://github.com/mennanov/limiters/actions/workflows/tests.yml/badge.svg)](https://github.com/mennanov/limiters/actions/workflows/tests.yml)\n[![codecov](https://codecov.io/gh/mennanov/limiters/branch/master/graph/badge.svg?token=LZULu4i7B6)](https://codecov.io/gh/mennanov/limiters)\n[![Go Report Card](https://goreportcard.com/badge/github.com/mennanov/limiters)](https://goreportcard.com/report/github.com/mennanov/limiters)\n[![GoDoc](https://godoc.org/github.com/mennanov/limiters?status.svg)](https://godoc.org/github.com/mennanov/limiters)\n\nRate limiters for distributed applications in Golang with configurable back-ends and distributed locks.  \nAny types of back-ends and locks can be used that implement certain minimalistic interfaces. \nMost common implementations are already provided.  \n\n- [`Token bucket`](https://en.wikipedia.org/wiki/Token_bucket)\n    - in-memory (local)\n    - redis\n    - memcached\n    - etcd\n    - dynamodb\n    - cosmos db\n\n    Allows requests at a certain input rate with possible bursts configured by the capacity parameter.  \n    The output rate equals to the input rate.  \n    Precise (no over or under-limiting), but requires a lock (provided).\n\n- [`Leaky bucket`](https://en.wikipedia.org/wiki/Leaky_bucket#As_a_queue)\n    - in-memory (local)\n    - redis\n    - memcached\n    - etcd\n    - dynamodb\n    - cosmos db\n\n    Puts requests in a FIFO queue to be processed at a constant rate.  \n    There are no restrictions on the input rate except for the capacity of the queue.  \n    Requires a lock (provided).\n\n- [`Fixed window counter`](https://konghq.com/blog/how-to-design-a-scalable-rate-limiting-algorithm/)\n    - in-memory (local)\n    - redis\n    - memcached\n    - dynamodb\n    - cosmos db\n\n    Simple and resources efficient algorithm that does not need a lock.  \n    Precision may be adjusted by the size of the window.  \n    May be lenient when there are many requests around the boundary between 2 adjacent windows.\n\n- [`Sliding window counter`](https://konghq.com/blog/how-to-design-a-scalable-rate-limiting-algorithm/)\n    - in-memory (local)\n    - redis\n    - memcached\n    - dynamodb\n    - cosmos db\n\n    Smoothes out the bursts around the boundary between 2 adjacent windows.  \n    Needs as twice more memory as the `Fixed Window` algorithm (2 windows instead of 1 at a time).  \n    It will disallow _all_ the requests in case when a client is flooding the service with requests.\n    It's the client's responsibility to handle a disallowed request properly: wait before making a new one again.\n\n- `Concurrent buffer`\n    - in-memory (local)\n    - redis\n    - memcached\n    \n    Allows concurrent requests up to the given capacity.  \n    Requires a lock (provided).\n\n## gRPC example\n\nGlobal token bucket rate limiter for a gRPC service example:\n```go\n// examples/example_grpc_simple_limiter_test.go\nrate := time.Second * 3\nlimiter := limiters.NewTokenBucket(\n    2,\n    rate,\n    limiters.NewLockerEtcd(etcdClient, \"/ratelimiter_lock/simple/\", limiters.NewStdLogger()),\n    limiters.NewTokenBucketRedis(\n        redisClient,\n        \"ratelimiter/simple\",\n        rate, false),\n    limiters.NewSystemClock(), limiters.NewStdLogger(),\n)\n\n// Add a unary interceptor middleware to rate limit all requests.\ns := grpc.NewServer(grpc.UnaryInterceptor(\n    func(ctx context.Context, req interface{}, info *grpc.UnaryServerInfo, handler grpc.UnaryHandler) (resp interface{}, err error) {\n        w, err := limiter.Limit(ctx)\n        if err == limiters.ErrLimitExhausted {\n            return nil, status.Errorf(codes.ResourceExhausted, \"try again later in %s\", w)\n        } else if err != nil {\n            // The limiter failed. This error should be logged and examined.\n            log.Println(err)\n            return nil, status.Error(codes.Internal, \"internal error\")\n        }\n        return handler(ctx, req)\n    }))\n```\n\nFor something close to a real world example see the IP address based gRPC global rate limiter in the \n[examples](examples/example_grpc_ip_limiter_test.go) directory.\n\n## DynamoDB\n\nThe use of DynamoDB requires the creation of a DynamoDB Table prior to use. An existing table can be used or a new one can be created. Depending on the limiter backend:\n\n* Partition Key\n  - String\n  - Required for all Backends\n* Sort Key\n  - String\n  - Backends:\n    - FixedWindow\n    - SlidingWindow\n* TTL\n  - Number\n  - Backends:\n    - FixedWindow\n    - SlidingWindow\n    - LeakyBucket\n    - TokenBucket\n\nAll DynamoDB backends accept a `DynamoDBTableProperties` struct as a paramater. This can be manually created or use the `LoadDynamoDBTableProperties` with the table name. When using `LoadDynamoDBTableProperties`, the table description is fetched from AWS and verified that the table can be used for Limiter backends. Results of `LoadDynamoDBTableProperties` are cached.\n\n## Azure Cosmos DB for NoSQL\n\nThe use of Cosmos DB requires the creation of a database and container prior to use.\n\nThe container must have a default TTL set, otherwise TTL [will not take effect](https://learn.microsoft.com/en-us/azure/cosmos-db/nosql/time-to-live#time-to-live-configurations).\n\nThe partition key should be `/partitionKey`.\n\n## Distributed locks\n\nSome algorithms require a distributed lock to guarantee consistency during concurrent requests.  \nIn case there is only 1 running application instance then no distributed lock is needed \nas all the algorithms are thread-safe (use `LockNoop`).\n\nSupported backends:\n- [etcd](https://etcd.io/)\n- [Consul](https://www.consul.io/)\n- [Zookeeper](https://zookeeper.apache.org/)\n- [Redis](https://redis.io/)\n- [Memcached](https://memcached.org/)\n- [PostgreSQL](https://www.postgresql.org/)\n\n## Memcached\n\nIt's important to understand that memcached is not ideal for implementing reliable locks or data persistence due to its inherent limitations:\n\n- No guaranteed data retention: Memcached can evict data at any point due to memory pressure, even if it appears to have space available. This can lead to unexpected lock releases or data loss.\n- Lack of distributed locking features: Memcached doesn't offer functionalities like distributed coordination required for consistent locking across multiple servers.\n\nIf memcached exists already and it is okay to handle burst traffic caused by unexpected evicted data, Memcached-based implementations are convenient, otherwise Redis-based implementations will be better choices.\n\n## Testing\n\nRun tests locally:\n```bash\nmake test\n```\nRun benchmarks locally:\n```bash\nmake benchmark\n```\nRun both locally:\n```bash\nmake\n```\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmennanov%2Flimiters","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fmennanov%2Flimiters","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmennanov%2Flimiters/lists"}