Keeping a busy account from taking every API worker

A shared worker pool is the simplest way to drain API requests, but a single FIFO queue can let one busy account crowd out the others. If one account adds 500 requests while three others add 10 each, those smaller batches may sit behind the burst even when their accounts have made no recent requests. A minimal alternative is one pending queue per account, a global cap of eight in-flight requests, and a cap of two per account. When a worker becomes free, pick the next eligible account in round-robin order and take its oldest request. The tradeoff is unused capacity when only one account is active. Letting that account borrow extra slots is an option, but I’d first check whether idle workers are a real problem.

Rate-limit responses should change which requests are eligible, not occupy a worker while a timer runs. If a response for one account says Retry-After: 90, record its next eligible time and return the worker to the pool; other accounts can keep moving. If the limit applies to an endpoint or the whole application instead, pause that scope rather than assuming it belongs to one account. Log the account, endpoint, time spent waiting, response status, and next eligible time. Global throughput alone can look healthy while one account consistently waits longest. How do you distribute worker slots across accounts, and what do you watch to catch unfair waits?

Round-robin keeps the 500-request burst from taking every dispatch turn. But if one account’s requests take 20 seconds and another’s take one, equal request counts do not mean equal worker time. When durations differ substantially, deficit round-robin can charge estimated worker time against each account’s credit, giving them fairer shares of capacity.

For example, reserve five seconds of account credit at dispatch. Record the worker start time; if the request completes 20 seconds later, charge the remaining 15 seconds, or refund credit if it finishes early. Using measured worker occupancy for the final charge keeps inaccurate duration estimates from permanently skewing each account’s share.