{"id":28766314,"url":"https://github.com/uppercasee/distributed-rate-limiter","last_synced_at":"2026-04-14T15:31:57.003Z","repository":{"id":294657211,"uuid":"986414316","full_name":"uppercasee/distributed-rate-limiter","owner":"uppercasee","description":"Scalable gRPC service for distributed, Redis-backed sliding window rate limiter.","archived":false,"fork":false,"pushed_at":"2025-05-27T01:49:23.000Z","size":80,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"main","last_synced_at":"2025-06-17T12:03:07.396Z","etag":null,"topics":["docker","go","grpc","rate-limiter","redis"],"latest_commit_sha":null,"homepage":"","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/uppercasee.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}},"created_at":"2025-05-19T15:14:12.000Z","updated_at":"2025-05-27T01:49:26.000Z","dependencies_parsed_at":"2025-05-26T01:15:19.401Z","dependency_job_id":null,"html_url":"https://github.com/uppercasee/distributed-rate-limiter","commit_stats":null,"previous_names":["uppercasee/distributed-rate-limiter"],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/uppercasee/distributed-rate-limiter","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/uppercasee%2Fdistributed-rate-limiter","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/uppercasee%2Fdistributed-rate-limiter/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/uppercasee%2Fdistributed-rate-limiter/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/uppercasee%2Fdistributed-rate-limiter/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/uppercasee","download_url":"https://codeload.github.com/uppercasee/distributed-rate-limiter/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/uppercasee%2Fdistributed-rate-limiter/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":31803216,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-04-14T11:13:53.975Z","status":"ssl_error","status_checked_at":"2026-04-14T11:13:53.299Z","response_time":153,"last_error":"SSL_connect returned=1 errno=0 peeraddr=140.82.121.5: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":["docker","go","grpc","rate-limiter","redis"],"created_at":"2025-06-17T12:00:50.834Z","updated_at":"2026-04-14T15:31:56.998Z","avatar_url":"https://github.com/uppercasee.png","language":"Go","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Distributed Rate Limiting Service (DRLS)\n\nRate limiting is a common mechanism used in modern systems to control the rate at which clients can access resources. It protects services from abuse, ensures fair usage, and helps manage traffic during high-load scenarios.\n\nThe Distributed Rate Limiting Service (DRLS) is designed to provide scalable, consistent rate limiting across multiple service instances. It is implemented as a gRPC service and backed by Redis, using a sliding window algorithm to track request activity in near real-time.\n\n## Core Concept\n\nAt its core, DRLS enforces limits on how many requests a specific client can make within a given time window. Instead of tracking counters per fixed interval, DRLS uses a **sliding window** approach, where each request is timestamped and stored temporarily in Redis. This allows it to provide smoother enforcement, avoiding burstiness allowed by fixed windows.\n\nFor example, if a client is allowed 100 requests per minute, the system ensures that the client does not exceed 100 requests in any 60-second rolling window, regardless of when the minute starts.\n\n## Redis as Central Store\n\nRedis is used as the single source of truth for request timestamps. All gRPC server replicas connect to the same Redis instance, which stores request data using sorted sets (`ZADD`, `ZREMRANGEBYSCORE`). This enables multiple server replicas to consistently enforce limits while sharing state across the cluster.\n\nEach request results in a timestamp being added to Redis under a key representing the client. Old timestamps are pruned, and the current request count is compared to the limit.\n\n## Distributed gRPC Servers\n\nTo scale the service horizontally, DRLS supports multiple gRPC server instances running in parallel. These are fronted by a load balancer (e.g., NGINX) that distributes traffic. All replicas are stateless and identical — they rely entirely on Redis to enforce limits, making it easy to scale up or down depending on load.\n\nThis architecture ensures that the rate limit is globally enforced, regardless of which replica handles the request, as long as they share access to the same Redis instance.\n\n## Sliding Window Algorithm\n\nThe sliding window algorithm used by DRLS avoids the abrupt resets that can occur with fixed windows. Instead of counting requests per strict interval (e.g., 12:00–12:01), it looks back over the last N seconds from the time of each incoming request and counts how many requests occurred during that period.\n\nThis provides more accurate enforcement and fairness, and helps smooth out spikes in traffic that could otherwise be allowed under a fixed window model.\n\n## TODO / Future Improvements\n\n- ~~Use **Redis Lua scripts** for atomic request handling to prevent race conditions.~~\n- Add support for **Redis Cluster / sharding** for better scalability and fault tolerance.\n- Integrate **Prometheus metrics exporter** for observability and performance monitoring.\n- Add **configurable rate limit policies** per client or API key.\n- Support **graceful Redis failover** and connection retry logic for high availability.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fuppercasee%2Fdistributed-rate-limiter","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fuppercasee%2Fdistributed-rate-limiter","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fuppercasee%2Fdistributed-rate-limiter/lists"}