A high-performance, distributed rate limiter built in Go. It uses Redis Lua scripts to ensure atomicity and prevent race conditions in concurrent environments.
- Distributed State: Uses Redis as the backend, allowing multiple API instances to share the same rate limits.
- Atomic Operations: Implements the "Fixed Window" algorithm via custom Lua scripts to guarantee thread safety.
- Concurrency Safe: Proven to handle concurrent requests without "leaking" excess traffic.
- Dockerized: Ready to run with a single command.
- Language: Go (Golang)
- Database: Redis (Alpine)
- Containerization: Docker & Docker Compose
- Testing: Custom concurrent load generator
-
Start Redis:
docker-compose up -d
-
Run the Server:
go run main.go
Server will start on
:8080. -
Run the Load Test:
go run load_test/attack.go
Load test results simulating 20 concurrent requests (Limit: 5/10s):
🚀 Starting Load Test...
✅ Request 10: ALLOWED
✅ Request 9: ALLOWED
✅ Request 1: ALLOWED
✅ Request 6: ALLOWED
✅ Request 7: ALLOWED
⛔ Request 14: BLOCKED
... (All subsequent requests blocked)
Test finished in 19.69ms