Rate Limiting¶
SnerdMQ includes a built-in token-bucket rate limiter that prevents your tasks from overwhelming third-party APIs. When you're bursting hundreds of LLM generation jobs, SnerdMQ automatically pauses dispatch to prevent 429 "Too Many Requests" errors.
How It Works¶
Rate limiting in SnerdMQ uses a rolling 60-second window per group:
- You assign tasks to a
rate_limit_group(e.g.,"openai_api") - You set a
max_per_minutecap for that group - The daemon tracks execution velocity for each group
- When the limit is hit, further tasks in that group are paused (not dropped)
- As the window slides and capacity frees up, paused tasks resume dispatching
This is backpressure, not rejection — tasks wait in the queue and execute as soon as capacity allows.
Configuration¶
| Parameter | Type | Description |
|---|---|---|
rate_limit_group |
string | Groups tasks for shared rate limiting (e.g., "anthropic", "sendgrid") |
max_per_minute |
int | Maximum task executions per 60-second rolling window for this group |
Code Examples¶
Multiple Rate Limit Groups¶
You can define independent rate limit groups for different services:
Group: "openai_api" → max 60/min
Group: "anthropic" → max 50/min
Group: "sendgrid" → max 100/min
Group: "db_writes" → max 200/min
Each group has its own independent rolling window. Tasks without a rate_limit_group execute immediately with no throttling.
Use Cases¶
- LLM API calls — Prevent 429 errors when bursting GPT-4 or Claude requests
- Email sending — Respect SendGrid/Mailgun rate limits
- Database writes — Throttle bulk inserts to avoid connection pool exhaustion
- Webhook dispatch — Stay within downstream webhook rate limits
- Payment processing — Respect Stripe/PayPal API quotas