How vaibhav7676-vrh/rate-limiter-service works
This is a multi-tenant rate-limiting API. A client submits a tenant, API key, and resource to /check; the service loads that tenant/resource policy, checks the corresponding token bucket in Redis, and returns an allow/deny result. The Redis Lua script makes the check atomic. The API records outcome and latency metrics for Prometheus and Grafana. The README also documents policy initialization and an in-memory token-bucket reference implementation. Edges reflect shown calls or documented integrations; the Lua implementation itself was not excerpted.
Main entry points: routes.py Check Endpoint · rate_limiter_service.py Limit Service · bucket_repository.py Bucket Repository · main.py FastAPI App
Components 15
API
- Check Endpoint
app/api/routes.py - Request Schemas
app/api/schemas.py - FastAPI App
app/main.py
Rate Limiting
- Limit Service
app/services/rate_limiter_service.py - Token Bucket Reference
app/algorithms/token_bucket.py
Redis Storage
- Bucket Repository
app/storage/bucket_repository.py - Atomic Lua Bucket
app/storage/lua/token_bucket.lua - Policy Repository
app/storage/policy_repository.py - Redis Client
app/storage/redis_client.py - Policy Initializer
scripts/init_policies.py
Observability
- Metrics
app/monitoring/metrics.py
Other components
- API Client
- Redis
- Prometheus
- Grafana Dashboard
Connections 15
- API Client → Check Endpoint: checks limits
README.md - FastAPI App → Check Endpoint: registers router
app/main.py - Check Endpoint → Request Schemas: accepts request
app/api/routes.py - Check Endpoint → Limit Service: checks limit
app/api/routes.py - Limit Service → Policy Repository: loads policy
app/services/rate_limiter_service.py - Limit Service → Bucket Repository: checks bucket
app/services/rate_limiter_service.py - Bucket Repository → Atomic Lua Bucket: loads script
app/storage/bucket_repository.py - Bucket Repository → Redis Client: evaluates script
app/storage/bucket_repository.py - Policy Repository → Redis Client: reads and writes
app/storage/policy_repository.py - Redis Client → Redis: connects to
app/storage/redis_client.py - Policy Initializer → Policy Repository: saves policies
scripts/init_policies.py - Check Endpoint → Metrics: records outcomes
app/api/routes.py - FastAPI App → Metrics: mounts endpoint
app/main.py - Prometheus → FastAPI App: scrapes metrics
README.md - Prometheus → Grafana Dashboard: feeds dashboard
README.md