Skip to content
pushqdocs
Get started

This pattern keeps your calls to a third-party API (a CRM, an email provider, a payment or AI API) under the provider’s documented rate limit. You send every call through one pushq queue whose rate limit matches the provider’s, and your handler passes the provider’s 429 and Retry-After back to pushq so the queue slows down when the provider asks it to.

Match the queue’s rate limit to the provider’s limit

Section titled “Match the queue’s rate limit to the provider’s limit”

Say the provider documents “25 requests per second, at most 10 concurrent requests”. Create one queue for that provider with a little headroom, then enqueue every call to it:

await pq.upsertQueue("crm-api", {
rateLimits: {
maxDispatchesPerSecond: 20, // provider allows 25/s; keep headroom
maxBurstSize: 20,
maxConcurrentDispatches: 10, // provider allows 10 in flight
},
retry: { maxAttempts: 20, minBackoffSeconds: 1, maxBackoffSeconds: 600 },
target: { baseUrl: "https://api.example.com" },
});
await pq.createTask("crm-api", { path: "/hooks/crm-sync", jsonBody: { contactId: 42 } });

pushq delivers each task to your endpoint (https://api.example.com/hooks/crm-sync), and your handler makes the provider call. The examples assume a client named pq (see install and configure an SDK). The text uses JSON field names; the SDKs use their language’s casing (maxDispatchesPerSecond in TypeScript and Java, max_dispatches_per_second in Python, MaxDispatchesPerSecond in Go and .NET).

Use this when a provider rejects or bans clients that exceed a documented requests-per-second, requests-per-minute or concurrency limit, and the calls can happen in the background.

Translate a provider rate limit into queue settings

Section titled “Translate a provider rate limit into queue settings”
Provider documents Queue setting Example
N requests per second rate_limits.max_dispatches_per_second = N, or a bit less 25/s → 20
N requests per minute max_dispatches_per_second = N / 60, and a small max_burst_size 120/min → 2, burst 0 (auto = 2)
One request every N seconds max_dispatches_per_second = 1 / N, max_burst_size = 1 every 5 s → 0.2, burst 1
At most N requests in flight rate_limits.max_concurrent_dispatches = N 10 concurrent → 10
A short burst above the steady rate rate_limits.max_burst_size = the burst burst of 50 → 50

Valid ranges: max_dispatches_per_second is greater than 0 and at most 10,000 (fractions are fine), max_burst_size is 0 to 10,000, and max_concurrent_dispatches is 1 to 10,000. A max_burst_size of 0 means auto: the rate rounded up, between 1 and 500.

Concurrency matters as much as rate when the provider is slow. At 20 dispatches per second and 3-second responses, 60 requests would be in flight; max_concurrent_dispatches: 10 caps that at 10, which in turn caps the real rate at about 3 per second. Set both.

Relay 429 and Retry-After from the provider

Section titled “Relay 429 and Retry-After from the provider”

When the provider says “slow down”, answer pushq with 429 Too Many Requests (or 503) and a Retry-After header. pushq then delays that task and briefly stops dispatching the whole queue.

app.post("/hooks/crm-sync", express.json(), async (req, res) => {
const r = await fetch("https://api.crm.example.com/v1/contacts", {
method: "POST",
headers: { Authorization: `Bearer ${process.env.CRM_TOKEN}`, "Content-Type": "application/json" },
body: JSON.stringify(req.body),
});
if (r.status === 429 || r.status === 503) {
// Pass the provider's back-off on to pushq.
res.set("Retry-After", r.headers.get("Retry-After") ?? "10");
return res.sendStatus(429);
}
res.sendStatus(r.ok ? 204 : 502);
});

These handlers are plain web code, so there is no curl tab. In production, also verify the webhook signature before calling the provider, and make the handler idempotent: a task can be delivered more than once.

The fallback of "10" seconds applies when the provider sends a 429 without Retry-After. Without the header, pushq treats a 429 as an ordinary failure: normal backoff and no queue cool-down.

pushq’s dispatcher enforces the limit on the server, at delivery time:

  1. Token bucket. Each queue has a bucket that holds up to max_burst_size tokens and refills at max_dispatches_per_second. A task is claimed for delivery only when a token is available.
  2. Concurrency cap. No new task is claimed while the queue has max_concurrent_dispatches requests in flight.
  3. Retries go through the same limits. A retry is a pending task like any other, so it uses a token and a concurrency slot. Retries can’t push you over the provider’s limit.
  4. 429 or 503 with Retry-After. When your endpoint answers 429 or 503 with a Retry-After header (seconds or an HTTP date):
    • that task’s next attempt is scheduled Retry-After from now instead of after its normal backoff, capped at the queue’s retry.max_backoff_seconds;
    • the whole queue stops claiming new tasks for Retry-After, capped at 30 seconds. Requests already in flight finish normally.

So a single 429 pauses the queue briefly and pushes the throttled task back by as much as the provider asked. See Retry-After and the queue cool-down for the retry details.

Share one rate limit across many producers

Section titled “Share one rate limit across many producers”

The limit belongs to the queue, not to the code that enqueues. Ten services, a cron job and a backfill script can all enqueue into crm-api at once; pushq still dispatches at most 20 per second with 10 in flight. You don’t need a distributed lock or a shared Redis counter.

To make that hold:

  • Route every call to the provider through the queue. Any code path that calls the provider directly uses up the same provider quota without pushq seeing it.
  • Use one queue per provider credential. Provider limits are usually per API key or per account. If each of your customers connects their own provider account, give each one a queue (see per-tenant queues).
  • Split by limit, not by caller. If the provider limits endpoints separately (for example, search versus writes), use one queue per limit: crm-api/search and crm-api/writes.

If the provider call needs no logic of your own, a task can target the provider’s URL directly: set url to the absolute URL and pass the provider’s auth header in the task’s headers (or once in the queue’s target.headers). pushq then sees the provider’s own 429 and Retry-After.

The trade-off is that the credential is stored with the task or queue and is returned by the API (task headers in the full view, queue target.headers on every read), and any non-2xx answer, including permanent errors like 400, is retried. A handler of your own keeps the secret in your service and lets you stop retrying errors that will never succeed.

  • Rate set at exactly the provider’s limit. Clock skew and the provider’s own window boundaries can still trip it. Leave 10 to 20 percent headroom.
  • Ignoring concurrency. A rate limit alone doesn’t stop slow responses from piling up in flight.
  • Calls outside the queue. Synchronous calls from your web app share the provider quota with the queue.
  • Short max_backoff_seconds. It caps how long a throttled task waits, regardless of Retry-After.
  • Watching the backlog. If the provider limit is lower than your enqueue rate, the queue grows. Check oldest_due_age_seconds and errors_last_1m from the queue stats to see whether you are falling behind.