Rate Limit and Queue with p-queue
01Problem
When an API pushes an external integration too hard, rate limits hit quickly and failures start to spread.
Solution
I put the critical outbound flow behind a queue with defined concurrency and pacing.
Impact
The integration stayed within real capacity, with less noise and less cascading failure downstream.
Snippet
TypeScript / Node.jsconst queue = new PQueue({
concurrency: 4,
intervalCap: 20,
interval: 1000,
});
export function enqueue(job: InvoiceJob) {
return queue.add(() => provider.send(job));
}