Introduction
A B2B inventory platform sets a simple limit: 100 requests per minute per API key. It stops a misbehaving script that once took the database down. It also starts rejecting a large customer's ERP integration every evening at 7 pm, when the ERP pushes the day's stock movements in a two-minute burst. The customer's IT team opens a ticket titled "Your API is unreliable."
B2B traffic is bursty by nature. Integrations run on schedules, users upload files at month-end, and batch jobs start at the top of the hour. A rate limiter that treats every burst as abuse punishes exactly the customers who integrate most deeply.
In this article you will learn how common rate-limiting algorithms behave under bursts, how to implement a per-tenant token bucket in Redis, how to weight expensive endpoints, and how to separate rate limits from concurrency limits.
How Algorithms Behave Under Bursts
Fixed windows count requests per calendar minute. They are simple but allow up to double the limit around window boundaries and reject everything after the limit is hit, even if the tenant was quiet for the previous hour.
Sliding windows smooth the boundary problem but still treat the limit as a hard ceiling over the window. The token buckets model what most B2B systems actually want: a bucket holds up to a maximum number of tokens (the allowed burst), refills at a steady rate (the sustained limit), and each request spends a token. A tenant that has been quiet can burst up to the bucket size; a tenant that is constantly busy is held to the refill rate.
A Per-Tenant Token Bucket in Redis
Run the bucket logic atomically in Redis with a Lua script so concurrent API servers share one view of each tenant's bucket.
-- KEYS[1] = bucket key, ARGV: capacity, refill_per_sec, now_ms, cost
local cap, rate, now, cost = tonumber(ARGV[1]), tonumber(ARGV[2]), tonumber(ARGV[3]), tonumber(ARGV[4])
local b = redis.call('HMGET', KEYS[1], 'tokens', 'ts')
local tokens = tonumber(b[1]) or cap
local ts = tonumber(b[2]) or now
tokens = math.min(cap, tokens + (now - ts) / 1000 * rate)
local allowed = tokens >= cost
if allowed then tokens = tokens - cost end
redis.call('HSET', KEYS[1], 'tokens', tokens, 'ts', now)
redis.call('PEXPIRE', KEYS[1], math.ceil(cap / rate * 1000) + 1000)
local retry_ms = allowed and 0 or math.ceil((cost - tokens) / rate * 1000)
return { allowed and 1 or 0, math.floor(tokens), retry_ms }
Set capacity and refill rate per plan. A plan might allow a sustained 10 requests per second with a bucket of 1,200, so a quiet integration can send a burst of over a thousand requests before being slowed. Return the remaining tokens and the retry delay in response headers so clients can pace themselves.
Weighting Expensive Endpoints
Not all requests cost the same. Fetching one order is cheap; exporting a year of orders or running a search with wildcards is not. Assign each endpoint a cost in tokens, such as 1 for simple reads, 5 for searches, and 50 for exports, and pass that cost to the limiter. This keeps the limit meaningful without forcing a separate limit for every endpoint.
Offer bulk endpoints that accept many records in one request. A customer importing 5,000 stock movements as 50 requests of 100 items each puts far less load on your system than 5,000 single-item calls and is much less likely to hit any limit.
Concurrency Limits Are Different
Rate limits control how many requests start per second. They do not stop a tenant from running 200 slow reports at once. Add a separate concurrency limit per tenant for expensive operations, implemented as a counter of in-flight requests that is decremented when each request finishes. For long-running work such as imports and exports, accept the request, queue it and return a job ID, so the tenant's burst becomes a queue rather than a wall of 429 responses.
Practical Examples: Real-World Use Cases
The inventory platform from the introduction switched to a token bucket with a burst size matched to its largest customers' nightly batches and a sustained rate that protected the database. Evening 429 errors from the ERP integration dropped to zero, while a script stuck in a retry loop was still slowed within seconds.
A B2B document platform weights OCR endpoints at 20 tokens and metadata reads at 1, so heavy processing cannot starve customers who are simply browsing.
A logistics SaaS moved bulk shipment creation to an asynchronous job endpoint with a per-tenant concurrency limit of three running jobs. Large customers stopped seeing rejections, and the platform's peak load became predictable.
Common Mistakes to Avoid
Using a fixed per-minute window as the only limit for bursty B2B integrations.
Limiting per API key when tenants spread traffic across many keys, which lets one tenant multiply its limit.
Treating every endpoint as equal cost.
Returning 429 without Retry-After or remaining-token headers.
Relying on rate limits to prevent slow-query overload instead of adding concurrency limits.
Best Practices: Actionable Tips
Measure real traffic per tenant before choosing burst and sustained values.
Apply limits per tenant first, then per user or key within the tenant.
Publish limits per plan and expose them in headers on every response.
Provide bulk and asynchronous endpoints for heavy workloads.
Alert when a tenant is throttled repeatedly, and contact them before they open a ticket.
Conclusion
Good rate limiting in B2B SaaS protects shared capacity without breaking scheduled integrations and month-end peaks. Use per-tenant token buckets with burst sizes that match real traffic, weight expensive endpoints, separate concurrency from rate, and give customers bulk and asynchronous options. The takeaway: limit sustained abuse, not legitimate bursts, and tell clients exactly where they stand.
Build Fair, Scalable APIs With Parallaxis
Parallaxis designs and builds multi-tenant SaaS APIs with rate limiting, bulk endpoints, and job queues tuned to how B2B customers really integrate. If throttling is causing customer complaints or outages, visit parallaxis.in to explore our SaaS development services or talk with our team.


