An open API service indexing awesome lists of open source software.

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

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.