Rate Limiting
SynDB enforces per-IP rate limiting using a token bucket algorithm.
Defaults
| Parameter | Default | Environment Variable |
|---|---|---|
| Requests per second | 100 | RATE_LIMIT_PER_SECOND |
| Burst capacity | 200 | RATE_LIMIT_BURST |
The bucket refills at the sustained rate. Burst capacity allows short spikes above the sustained rate.
Client IP Detection
The rate limiter identifies clients by IP address, checked in order:
X-Forwarded-Forheader (first address)X-Real-IPheader- Localhost (fallback for direct connections)
Behind a reverse proxy, ensure X-Forwarded-For is set correctly.
Response on Limit
When the rate limit is exceeded:
HTTP/1.1 429 Too Many Requests
Retry-After: 1
Too many requests
Client Handling
Respect the Retry-After header and implement exponential backoff:
import time
import requests
def request_with_backoff(url, headers, max_retries=3):
for attempt in range(max_retries):
resp = requests.get(url, headers=headers)
if resp.status_code != 429:
return resp
wait = int(resp.headers.get("Retry-After", 1)) * (2 ** attempt)
time.sleep(wait)
raise Exception("Rate limited after retries")
For batch operations, throttle to well under 100 req/s to leave headroom for interactive use.