Go • Prometheus • Grafana
This repo contains five independent reference implementations of the most common rate-limiting algorithms.
Click on an algorithm for details
- Docker and Docker Compose — for containerized deployments
- vegeta — for load testing
- Prometheus — metrics collection
- Grafana — metrics visualization
For detailed instructions and configuration for each algorithm, please refer to the README.md file in its respective directory.
- Navigate to the directory of the algorithm you wish to run (e.g.,
cd FixedWindowCounter). - Start the services:
docker-compose up -d - Open Grafana at http://localhost:3000 and import the dashboard from
grafana.json. - Start hammering the endpoint and watch the metrics in real time:
# Example load test with vegeta
echo "GET http://localhost:8080/" | vegeta attack -rate=50 -duration=30s | vegeta reportRateLimiter/
.
├── FixedWindowCounter
│ ├── docker-compose.yml
│ ├── Dockerfile
│ ├── fixedwindow.go
│ ├── fixedwindow_test.go
│ ├── go.mod
│ ├── go.sum
│ ├── grafana.json
│ ├── main.go
│ ├── prometheus.yml
│ └── readme.md
├── images
│ ├── FixedWindow.png
│ ├── LeakyBucket.png
│ ├── SlidingWindowCounter.png
│ ├── SlidingWindowLog.png
│ └── tokenBucket.png
├── LeakyBucket
│ ├── docker-compose.yml
│ ├── Dockerfile
│ ├── go.mod
│ ├── go.sum
│ ├── grafana.json
│ ├── leakybucket.go
│ ├── leakybucket_test.go
│ ├── main.go
│ ├── prometheus.yml
│ └── readme.md
├── productionreadydockerfile.txt
├── readme.md
├── SlidingWindowCounter
│ ├── docker-compose.yml
│ ├── Dockerfile
│ ├── go.mod
│ ├── go.sum
│ ├── grafana.json
│ ├── main.go
│ ├── prometheus.yml
│ ├── readme.md
│ ├── slidingWindowCounter.go
│ └── slidingWindowCounter_test.go
├── SlidingWindowLog
│ ├── Deque.go
│ ├── docker-compose.yml
│ ├── Dockerfile
│ ├── go.mod
│ ├── go.sum
│ ├── grafana.json
│ ├── main.go
│ ├── prometheus.yml
│ ├── readme.md
│ ├── slidingWindowLog.go
│ └── slidingWindowLog_test.go
└── tokenBucket
├── docker-compose.yml
├── Dockerfile
├── go.mod
├── go.sum
├── grafana.json
├── main.go
├── prometheus.yml
├── readme.md
├── tokenBucket.go
└── tokenBucket_test.go
This is just my understanding and attempt at implementing the concept and diagram(which was made by me).
If something’s off in the implementation — well, that’s part of the learning journey 🚀