Rate limiting is enabled by default on all routes. No configuration is required for basic protection, but tuning the values for your specific traffic patterns is recommended.
How It Works
- Every incoming API request is tracked by the client’s IP address.
- Each rate limiter defines a time window and a maximum number of requests allowed within that window.
- If a client exceeds the limit, they receive a
429 Too Many Requestsresponse until the window resets. - Standard rate limit headers are included in API responses so clients can monitor their remaining quota.
If DataBrain runs behind a reverse proxy or load balancer (NGINX, AWS ALB, Cloudflare, etc.), make sure the proxy forwards the real client IP. DataBrain checks the
X-Client-IP header first and falls back to the standard X-Forwarded-For header (via Express’s built-in trusted proxy support) to identify individual clients. Without proper proxy configuration, all traffic may appear to come from a single IP and get rate-limited together.Environment Variables
Set these in your.env file for the DataBrain API service (Express backend). All values represent the maximum number of requests per client IP within the given time window.
General API Rate Limit
Maximum requests per IP across all API endpoints within a 2-minute window.This is the global rate limiter — it applies to every request before any route-specific limits are checked.
Authentication Rate Limits
These protect login and identity-related endpoints against brute-force and credential-stuffing attacks.Maximum requests per IP to authentication endpoints within a 1-minute window.Covers: sign-in, sign-up, SSO, password reset, invitation acceptance, and related auth flows.
Maximum requests per IP to the token refresh endpoint within a 1-minute window.Controls how frequently a client can request new access tokens.
Maximum requests per IP to OTP (one-time password) endpoints within a 1-minute window.Covers OTP generation and verification.
Other Rate Limits
Maximum requests per IP to email-sending endpoints within a 1-minute window.Covers invitation emails, verification re-sends, and scheduled report triggers.
Maximum requests per IP to the demo database onboarding endpoint within a 1-minute window.Only relevant if you use the built-in demo database onboarding flow.
Quick Reference
| Variable | Default | Window | Protects |
|---|---|---|---|
RATE_LIMIT | 500 | 2 min | All API routes (global) |
AUTH_ROUTE_RATE_LIMIT | 30 | 1 min | Login, sign-up, SSO, password reset |
REFRESH_ROUTE_RATE_LIMIT | 30 | 1 min | Token refresh |
OTP_RATE_LIMIT | 50 | 1 min | OTP generation and verification |
EMAIL_RATE_LIMIT | 50 | 1 min | Invitation and verification emails |
ONBOARDING_DEMO_DATABASE_RATE_LIMIT | 50 | 1 min | Demo database onboarding |
Configuration Example
Add these to your DataBrain API.env file:
Tuning for Your Deployment
The default values are a good starting point for most deployments. Here’s how to think about adjusting them:When to lower the defaults
When to lower the defaults
If you have a small user base (under ~100 users) and want tighter security, you can reduce limits — for example, halving
RATE_LIMIT to 250 or lowering AUTH_ROUTE_RATE_LIMIT to 15. Fewer legitimate users means fewer requests per IP, so tighter limits are less likely to cause false positives.When to raise the defaults
When to raise the defaults
Increase limits if you see legitimate requests getting
429 errors. Common scenarios:- High-traffic embedded dashboards — Many end users loading dashboards simultaneously can generate significant API traffic. Increase
RATE_LIMITas needed (e.g., to1000or higher). - Shared IP / corporate NAT — If many users share one public IP (offices, VPNs), they collectively consume one IP’s quota. Raise
RATE_LIMITproportionally. - Automated workflows — CI/CD pipelines, bulk token generation, or automated testing can trigger auth limits. Raise
AUTH_ROUTE_RATE_LIMITorREFRESH_ROUTE_RATE_LIMITfor those environments.
How to find the right values
How to find the right values
- Start with the defaults — they work well for most medium-sized deployments.
- Monitor 429 responses in your logs or monitoring stack.
- Increase incrementally if legitimate traffic is being blocked — double the value and observe.
- Avoid setting limits excessively high — very high limits (e.g.,
RATE_LIMIT=100000) effectively disable rate limiting and remove protection against abuse.
What Happens When a Limit Is Hit
When a client exceeds a rate limit:- The API responds with HTTP status
429 Too Many Requests. - The response body contains a descriptive error message (e.g., “Too many requests, please try again later”).
- The client should wait until the current window expires before retrying.
Response headers
Response headers
Responses include standard rate limit headers that clients can use to manage their request pace:
RateLimit— Combined header showing the current limit, remaining requests, and reset time (e.g.,limit=500, remaining=498, reset=120)RateLimit-Policy— Describes the rate limit policy in effectRetry-After— Seconds to wait before retrying (included on 429 responses)
Best practice for handling 429 errors
Best practice for handling 429 errors
If your backend integration receives a
429 response:- Read the
Retry-Afterheader to know when to retry. - Implement exponential backoff — wait 1s, then 2s, then 4s, etc.
- Do not retry immediately in a tight loop — failed requests still count against the limit, so rapid retries will consume the next window’s quota as soon as it resets.
- Guest tokens are reusable — consider caching them on your backend rather than generating a new one for every page load. Refresh before the token’s
expiryTimeto avoid401errors.
Best Practices
Always set RATE_LIMIT explicitly
Always set RATE_LIMIT explicitly
We strongly recommend explicitly setting the
RATE_LIMIT variable in your .env file rather than relying on the default. This ensures predictable behavior and makes your configuration self-documenting.Configure your reverse proxy to forward real IPs
Configure your reverse proxy to forward real IPs
Rate limiting is based on client IP. If DataBrain sits behind NGINX, a cloud load balancer, or Cloudflare, ensure the proxy forwards the original client IP. DataBrain checks the
X-Client-IP header first, then falls back to X-Forwarded-For (via Express trusted proxy support). Either header works — just make sure at least one is set.Without this, all requests appear to come from the proxy’s IP, causing legitimate users to be rate-limited together.Cache guest tokens on your backend
Cache guest tokens on your backend
Guest tokens are reusable — once created, the same token can authenticate multiple requests until it expires. Instead of calling the guest token API on every page load, cache the token on your backend and reuse it for the same user and parameter combination.If you set an
expiryTime, make sure to refresh the token before it expires. Expired tokens are periodically cleaned up and will return a 401 error once removed.Keep auth limits low
Keep auth limits low
Authentication endpoints are the most targeted by brute-force attacks. Keep
AUTH_ROUTE_RATE_LIMIT and OTP_RATE_LIMIT conservative (30–50 per minute) unless you have a specific reason to increase them.Monitor 429 responses in production
Monitor 429 responses in production
Track 429 responses in your monitoring stack (DataDog, Grafana, etc.). A spike in 429s may indicate either an attack (good — the rate limiter is protecting you) or limits that are too tight for your traffic (adjust accordingly).
Troubleshooting
All users are being rate-limited together
All users are being rate-limited together
Cause: The reverse proxy is not forwarding the real client IP.Fix: Configure your proxy to forward the real client IP. DataBrain checks For AWS ALB or Cloudflare,
X-Client-IP first, then X-Forwarded-For. For NGINX, add:X-Forwarded-For is typically set automatically, but verify the header is reaching DataBrain.Embedded dashboards intermittently fail with 429
Embedded dashboards intermittently fail with 429
Cause: High-traffic pages generating too many API calls per IP.Fix:
- Increase
RATE_LIMITto accommodate your peak traffic. - Cache guest tokens on your backend to reduce token-creation calls.
- Ensure dashboards use caching (Workspace Settings → Cache Settings) to reduce repeated data queries.
Login page shows 'Too many requests' error
Login page shows 'Too many requests' error
Cause: Auth rate limit exceeded, possibly from automated tests or repeated failed logins.Fix: Wait 1 minute for the window to reset. If this happens regularly for legitimate users, consider increasing
AUTH_ROUTE_RATE_LIMIT slightly (e.g., from 30 to 50).
