https://github.com/stoppieboy/rate-limiter
A High Throughput Rate Limiter
https://github.com/stoppieboy/rate-limiter
gin-gonic golang lua prometheus redis
Last synced: 7 months ago
JSON representation
A High Throughput Rate Limiter
- Host: GitHub
- URL: https://github.com/stoppieboy/rate-limiter
- Owner: stoppieboy
- Created: 2025-09-02T13:21:07.000Z (7 months ago)
- Default Branch: main
- Last Pushed: 2025-09-06T14:02:35.000Z (7 months ago)
- Last Synced: 2025-09-06T15:29:12.626Z (7 months ago)
- Topics: gin-gonic, golang, lua, prometheus, redis
- Language: Go
- Homepage:
- Size: 21.5 KB
- Stars: 0
- Watchers: 0
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# ๐ฆ High-Throughput Rate Limiter (Gin + Redis + Lua + Prometheus)
A blazing-fast, production-ready rate limiter built in Go (Gin), powered by Redis Lua scripts for atomic token bucket operations, and instrumented with Prometheus & Grafana for real-time monitoring and observability.
โจ Features
โก High Throughput โ Uses Redis Lua scripts for atomic token bucket updates with minimal latency.
๐ก Distributed & Consistent โ Works across multiple Gin instances using Redis as a shared store.
๐ Configurable โ Easily set bucket size, refill rate, and key granularity (per user/IP/endpoint).
๐ Metrics & Observability โ Exposes Prometheus metrics at /metrics endpoint for scraping.
๐งฉ Gin Middleware โ Drop-in middleware for any Gin project.
๐งช Tested โ Unit tests for Lua script, middleware, and metrics.
## โ๏ธ How It Works
### 1. Token Bucket Algorithm
- Each request tries to consume a token from its bucket.
- If available โ token is decremented and request proceeds.
- If empty โ request is rejected with 429 Too Many Requests.
### 2. Redis Lua Script
- Atomic refill & consume in a single round trip.
- Prevents race conditions under high concurrency.
### 3. Prometheus Integration
- Exposes metrics: allowed requests, rejections, bucket usage, request latency.
- Compatible with Grafana dashboards for monitoring.