Rate Limit Configuration
The API uses token bucket algorithm for rate limiting, implemented withgolang.org/x/time/rate.
OAuth Endpoints
Authentication endpoints have stricter rate limits to prevent brute force attacks:Rate Limit: 5 requests per 12 seconds per IP addressBurst Size: 5 requests
GET /oauth/loginGET /oauth/callback
internal/api/routes.go:28
API Endpoints
General API endpoints have more generous rate limits for normal application usage:Rate Limit: 30 requests per 2 seconds per IP addressBurst Size: 30 requests
POST /api/v1/reservations- Create reservationGET /api/v1/reservations- Get reservationsDELETE /api/v1/reservations/{id}- Cancel reservation
internal/api/routes.go:29
This configuration allows clients to make up to 30 requests immediately, then sustains a rate of 1 request every 2 seconds (0.5 requests/second).
Health Check Endpoint
The health check endpoint (
GET /api/v1/health) is not rate limited to allow unrestricted monitoring.internal/api/routes.go:35
How Rate Limiting Works
Token Bucket Algorithm
The API uses the token bucket algorithm:- Each IP address gets a virtual “bucket” with a maximum capacity (burst size)
- Tokens are added to the bucket at a constant rate
- Each request consumes one token
- If no tokens are available, the request is rejected with
429 Too Many Requests
IP Address Detection
The rate limiter identifies clients by their IP address:internal/middleware/ratelimit.go:93-111
Visitor Cleanup
To prevent memory leaks, the rate limiter automatically cleans up stale visitor records:- Cleanup Interval: Every 3 minutes
- Stale Threshold: Visitors inactive for > 3 minutes are removed
internal/middleware/ratelimit.go:40-62
Rate Limit Responses
When Rate Limit is Exceeded
When a client exceeds the rate limit, the API returns: Status Code:429 Too Many Requests
Headers:
internal/middleware/ratelimit.go:81-85
Retry-After Header
TheRetry-After header is always set to 6 seconds, providing a consistent hint for when to retry the request.
Clients should respect the
Retry-After header and implement exponential backoff for better reliability.Best Practices
Handling Rate Limits
Implement Exponential Backoff
For multiple consecutive rate limit errors, increase wait time exponentially
Rate Limit Monitoring
When rate limits are exceeded, the server logs warnings:internal/middleware/ratelimit.go:82
Monitor these logs to identify clients that frequently hit rate limits and may need optimization.
Example: Client Implementation
Rate Limit Summary
| Endpoint Group | Rate | Burst | Interval | Requests/Minute |
|---|---|---|---|---|
| OAuth endpoints | 5/12s | 5 | 12 seconds | ~25 |
| API endpoints | 30/2s | 30 | 2 seconds | ~30 |
| Health check | Unlimited | N/A | N/A | Unlimited |
All rate limits are applied per IP address and are independent of authentication status.