All field guides

FIELD GUIDE Published

Queue fairness and backpressure: noisy neighbors, fair queuing, jitter

Give each tenant its own logical queue, dispatch across them with deficit round robin, which comes close to fair queuing's fairness at O(1) work per job when each quantum is at least the largest job, and cap each tenant's running jobs, lending idle workers: in October 2025 one GitLab group's security policy change generated thousands of jobs that crowded out other work on the shared catchall Sidekiq shard even though the worker classes involved had per-worker concurrency limits of 200, and the catchall queue's Apdex recovered from 1% only after GitLab raised the shards' pod limits. Push back on producers as the backlog grows, and make retried jobs re-enter behind fresh work, not ahead of it. Retry at one layer only, with capped exponential backoff, full jitter and a retry budget: in the AWS Builders' Library example, five layers that each make three attempts raise database load 243x.

Written with AI and checked against the cited sources before publication.

The mechanism

A shared job queue with a fixed worker pool is a single line. A job's wait is the work queued ahead of it divided by the rate the pool drains it. One tenant's bulk import puts every other tenant behind it. Amazon's SQS documentation names both ways a tenant becomes the noisy neighbor: "by sending a larger volume of messages than other tenants, or when consumers take longer to process messages from that particular tenant." A tenant whose jobs take ten times longer occupies ten times the workers at the same job count.

Autoscaling does not fix it. The same page says that at high throughput "over-scaling the consumer fleet to absorb every burst is impractical, and even with auto-scaling, the delay before new consumers come online can let backlogs form." And a backlog is expensive to pay back. In an Amazon Builders' Library example of one customer's unthrottled spike, with operators taking about 30 minutes to respond and a queue holding "10x the capacity that the consumer side was scaled to", "it would take 300 minutes for the system to work through the backlog and recover."

Fair queuing: one logical queue per tenant

The fix is to stop serving the jobs in arrival order and serve the tenants in turn. Fair queuing does this with near-perfect fairness, but the Shreedhar and Varghese paper notes that it costs O(log(n)) work per packet, where n is the number of active flows. Their deficit round robin (SIGCOMM 1995) gets nearly the same fairness for O(1) work, provided each quantum is at least the largest packet.

Each tenant gets its own queue, a Quantum (its share) and a DeficitCounter, and an ActiveList holds only the queues with work. On its turn a queue may send up to Quantum + DeficitCounter worth of work; what it cannot use carries over, and a queue that empties resets to 0 and leaves the list. Weights are quanta: a flow with twice the quantum gets "twice the bandwidth" when both are active.

The paper proves that a backlogged flow's shortfall stays within Max, the largest packet, and that the work is O(1) "if for all i, Quantum_i ≥ Max", because each visit then sends at least one item. It also says DRR "is also applicable to other scheduling problems where servicing cannot be broken up into smaller units", which is exactly a job. So measure the quantum in worker-seconds, not in jobs, and make it at least your largest job; otherwise a tenant of slow jobs still wins on job count. A job's cost is known only when it finishes, so charge the actual worker-seconds then and let the deficit go negative.

Fewer queues than tenants: hashing and shuffle sharding

You rarely want a queue per tenant. Amazon's answer is shuffle sharding. In the Builders' Library example of eight workers, giving each customer two of them makes 28 possible pairs, so "the scope of impact due to a problem is just 1/28th", "7 times better than regular sharding." For servers, as in Route 53, it depends on clients being fault tolerant and retrying on the other members of their shard; for queues, the producer makes that choice at enqueue time.

AWS Lambda applies it to queues: it "provisions a fixed number of queues, and hashes each customer to a small number of queues", and on each enqueue picks the one of them with the fewest messages. Kubernetes API Priority and Fairness (APF, stable since v1.29) does the same inside the API server. Each priority level has queues, a handSize (how many queues each flow is dealt) and a queueLengthLimit; "the maximum number of queued requests possible from a single flow is handSize * queueLengthLimit."

Concurrency caps and borrowing

Fair dispatch decides who goes next. It does not stop one tenant's slow jobs from holding every worker that is already running. For that, cap concurrency per tenant or per workload. Amazon uses "separate thread pools for each workload". A hard cap leaves workers idle when only one tenant is busy, so APF lets priority levels lend unused seats and borrow others', within bounds set as percentages of each level's nominal limit (lendablePercent sets how much it may lend).

Admission control, backpressure and shedding

Queues hide overload, so push back before the queue fills:

  • Admission control. Per-tenant quotas in a token bucket: in Amazon's example, a client limited to 1,000 transactions per second that spikes to 3,000 gets its 1,000, and "the other 2,000 TPS would be rejected". Its warning: "if the burst capacity is too large it defeats the protections of rate limiting."
  • Backpressure. Amazon suggests scaling "an inbound throttle limit (inversely) proportionally to backlog size", rejecting more at the producer as the queue grows.
  • Shedding. "Load shedding is the act of cheaply rejecting work instead of spending limited resources on it." Bound how long a request sits in a queue, and if its caller has already given up, skip the work: "the last thing a system should do in an overload situation, where capacity is constrained, is waste work." In queues: a TTL on stale work, and spilling excess into a separate queue, which "approximates a priority queue."

Retries, backoff and jitter

"Retries are 'selfish.'" In the Builders' Library example, a call goes five services deep to a database, with three tries at each layer: "If each layer retries independently, the load on the database will increase 243x, making it unlikely to ever recover." The rules that follow:

  • Retry at one layer only.
  • Give retries a budget: a local token bucket "allows all calls to retry as long as there are tokens, and then retry at a fixed rate when the tokens are exhausted", in the AWS SDK since 2016.
  • Back off exponentially with a cap, and add jitter. In the AWS simulator, full jitter is random.uniform(0, v), where v = min(self.cap, pow(2, n)*self.base) and n counts failed attempts, starting at 1. In Marc Brooker's simulation of 100 contending clients, jitter cut the call count "by more than half", and un-jittered backoff was "the clear loser".
  • Only retry what is idempotent: "APIs with side effects aren't safe to retry unless they provide idempotency."

Queues add redelivery: a job that outlives its SQS visibility timeout runs again while the first copy still runs, and under load "it causes an already overloaded service to essentially fork-bomb itself." Heartbeat long jobs.

Worked numbers

One bulk import, one small tenant. Illustrative: 20 workers, each job takes 2 seconds. Tenant A enqueues 6,000 jobs at 0 seconds; tenant B enqueues 10 jobs one second later.

  • *Shared FIFO.* A's jobs take 6,000 × 2 ÷ 20 = 600 seconds. B's 10 start when A's are gone and finish at 602 seconds, ten minutes for twenty seconds of work.
  • *Cap A at 15 workers.* Five workers stay free, so B finishes at 5 seconds. A now takes 6,000 × 2 ÷ 15 = 800 seconds, and when B is not there those five workers sit idle: a quarter of the pool.
  • *Round robin by tenant (DRR with equal quanta).* When the first 20 jobs finish at 2 seconds, the 20 free workers alternate between A and B, so B gets 10 and finishes at 4 seconds. A finishes at 602 seconds, two seconds later than with FIFO, and no worker is idle while there is work.
A 6,000-job import and a 10-job tenant on 20 workers: when each finishesBar chart of Small tenant B done, Bulk tenant A done across 3 categories.Small tenant B doneBulk tenant A doneShared FIFO602 s600 sCap A at 15 workers5 s800 sRound robin by tenant4 s602 slog scale
Figure 1. A 6,000-job import and a 10-job tenant on 20 workers: when each finishes Illustrative: 20 workers, 2 s per job, tenant A enqueues 6,000 jobs at 0 s, tenant B enqueues 10 jobs at 1 s
Data as text
Small tenant B done (s)Bulk tenant A done (s)
Shared FIFO602600
Cap A at 15 workers5800
Round robin by tenant4602

The cap protects B but wastes capacity; fair dispatch protects B and keeps the pool busy. Use both when one tenant's jobs are slow, since round robin alone still lets long-running jobs fill every worker between turns.

How many queues for shuffle sharding. The Kubernetes APF documentation publishes the probability that a light flow (a "mouse") is starved because every queue in its hand is shared with a heavy flow (an "elephant"). With 16 elephants and 64 queues, a hand of 8 fails 35.9% of the time and a bigger hand of 10 fails 50.0%; keeping the hand at 8 and doubling to 128 queues cuts it to 2.7%, and a hand of 6 from 1,024 queues to about 0.45 in a million. The documentation's price for more queues is "increased memory usage", so add queues before you raise the hand size.

Kubernetes APF: chance a light flow is starved by 16 heavy flowsBar chart of 16 heavy flows across 6 categories.hand 10, 32 queues975,310 per millionhand 10, 64 queues499,999 per millionhand 8, 64 queues359,351 per millionhand 8, 128 queues27,462 per millionhand 7, 256 queues671 per millionhand 6, 1024 queues0.452 per millionlog scale
Figure 2. Kubernetes APF: chance a light flow is starved by 16 heavy flows Source: Kubernetes documentation, API Priority and Fairness, table Example Shuffle Sharding Configurations
Data as text
16 heavy flows (per million)
hand 10, 32 queues975,310
hand 10, 64 queues499,999
hand 8, 64 queues359,351
hand 8, 128 queues27,461.7
hand 7, 256 queues670.966
hand 6, 1024 queues0.451741

What a retry budget buys. The 243 is 3 to the power 5. The source says "three retries at each layer", but its arithmetic ("first three tries, then nine tries") counts three attempts per layer; three retries after a first try would be 4 to the power 5, 1,024 times. Illustrative: a retry budget of 10% of calls per layer caps the worst case at 1.1 to the power 5, about 1.6 times the load, and one retrying layer with three attempts at 3 times.

How it fails

  • A per-worker-class limit that is not a per-tenant limit (GitLab, 30 October 2025). From 15:00 to 17:55 UTC, background jobs on GitLab.com were delayed. "A single group security policy change generated thousands of jobs", "overwhelming the queue even with concurrency limits in place": the worker classes involved had limits of 200 each, and Security::SyncProjectPolicyWorker "dominated processing for a period, crowding out other jobs" on the shared catchall Sidekiq shard, with WebHooks::LogExecutionWorker also contributing. After the team raised the shards' pod maximums, "the Apdex score for the catchall queue recovered from 1% to 95.5%." The review names no per-tenant fix; its follow-ups are to lower the shards' maximum replicas again and investigate the worker. Our reading: a limit per job class caps the class, not the one tenant inside it.
  • Retries that jumped the queue (Buttondown, 9 September 2026). A very large send started at 13:05 UTC and ran within SLA for hours. Each batch over the per-minute sending cap was re-queued "with its original deadline", and because pollers "prioritize executing background jobs that have earlier SLAs", every poller would "identify these redriven batches as the most important and starve the other jobs." At 18:15 UTC throughput fell to around 20% of the day's earlier level. The worker fleet scaled to its maximum of 40, held most of the shared database connection pool and, with an admin page querying the primary instead of a replica, took the dashboard down from about 18:35 to 20:35 UTC. The large send was 94% of the delayed batches; 26 other newsletters "were simply queued behind it." The backpressure lesson: scaling workers from 40 down to 10 was "the single most effective action of the hour", while pausing the large send "has no measurable effect on the queue." Buttondown fixed the scheduling bugs; a retry must re-enter behind fresh work, or within its tenant's share.
  • Back-off that did not back off (AWS us-east-1, 7 December 2021). At 7:30 AM PST, automated capacity scaling "triggered an unexpected behavior from a large number of clients inside the internal network." Delays between AWS's internal and main networks caused "even more connection attempts and retries"; EC2 API errors rose from 7:33 AM and Route 53 changes were blocked until 2:30 PM. Its clients "have well tested request back-off behaviors", but "a latent issue prevented these clients from adequately backing off during this event." Network devices recovered at 2:22 PM PST, STS at 4:28 PM, and EventBridge cleared its backlog at 6:40 PM. Backoff you have not tested under real congestion is a hope.
  • One new client against a shared control plane (OpenAI, 11 December 2024). From 3:16 to 7:38 PM PST, "all OpenAI services experienced significant degradation or complete unavailability." A new telemetry service "caused every node in each cluster to execute resource-intensive Kubernetes API operations" whose cost scaled with cluster size, overwhelming the API servers; services using the control plane for DNS failed when cached records expired. To remove the service, engineers needed the control plane, "which we could not do due to the increased load to the Kubernetes API servers." OpenAI's follow-ups start with phased rollouts that watch control-plane health, then break-glass access and "dynamic rate limiters" for cluster-startup resources. Our reading: give every new client class its own admission budget before its first deploy, such as an APF FlowSchema mapped to a priority level with a small share of seats.
How a redriven batch starved a shared job queue1. Large send → Job queue: one large broadcast, in batches. 2. Pollers → Job queue: batch over rate cap: re-queue. 3. Pollers → Job queue: keeps its original deadline. 4. Job queue → Pollers: earliest deadline first: redriven batch (the harmful step). 5. After a pause: Pollers → Job queue: still capped: re-queue again. 6. Other sends → Job queue: 26 newsletters wait behind it.Large sendJob queuePollersOther sendsone large broadcast, in batchesbatch over rate cap: re-queuekeeps its original deadlineearliest deadline first: redriven batchtime passesstill capped: re-queue again26 newsletters wait behind it
Figure 3. How a redriven batch starved a shared job queue Source: Buttondown, Web app and email delays, incident of 9 September 2026
Steps as text
  1. Large send → Job queue: one large broadcast, in batches
  2. Pollers → Job queue: batch over rate cap: re-queue
  3. Pollers → Job queue: keeps its original deadline
  4. Job queue → Pollers: earliest deadline first: redriven batch (the harmful step)
  5. After a pause: Pollers → Job queue: still capped: re-queue again
  6. Other sends → Job queue: 26 newsletters wait behind it

Decision table

OptionWhat it costsChoose it when
Shared FIFO queueOne tenant's burst or slow jobs delay everyone; backlog recovery takes spare capacityOne tenant, or tenants who can tolerate each other's bursts
Per-tenant logical queues with deficit round robinScheduler state per active tenant; quanta measured in cost, not job countMany tenants share a pool and quiet tenants' wait time matters
Shuffle sharding tenants into a fixed set of queuesSome collisions; producers pick the least-loaded queue in their shard (Lambda, APF)Too many tenants for a queue each; you want blast radius proven small
Per-tenant concurrency capIdle workers when one tenant is alone, unless you allow borrowingSome tenants' jobs are slow; fair dispatch alone still lets them fill the pool
Admission control (token bucket quotas)Rejected work at the edge; tuning burst sizeYou can tell a producer no at enqueue time
Backpressure from backlog sizeProducers see more rejections as the queue growsProducers can slow down or retry later
Load shedding and job TTLs, spillover queuesSome work is dropped or delayed on purposeOld work loses value, or fresh work matters more than the backlog
Retries at one layer, capped exponential backoff, full jitter, retry budgetSlower recovery for individual callsAlways; with idempotency keys for anything with side effects
Managed fairness (SQS fair queues with a MessageGroupId per tenant, Kubernetes APF)Less control; SQS protects quiet tenants' dwell time but "does not limit the consumption rate per tenant"You already run on SQS standard queues or the Kubernetes API, and need protection now

A check you can run this week

Run a noisy-neighbor drill in staging. Pick a quiet tenant and record its p99 time from enqueue to start. Then have one test tenant enqueue ten times its normal hourly volume and watch the quiet tenant's p99 over the next hour. If it rises with the backlog, you have a shared line.

Then put this question to the team: when a job is retried or re-queued, where does it go? To the front, with its old deadline, or behind fresh work and inside its tenant's share? If your job table lives in Postgres, this query shows who holds the pool right now (it assumes jobs(tenant_id, state, enqueued_at); map it to your schema):

SELECT tenant_id,
       count(*) FILTER (WHERE state = 'running') AS running,
       count(*) FILTER (WHERE state = 'queued')  AS queued,
       now() - min(enqueued_at) FILTER (WHERE state = 'queued') AS oldest_wait
FROM jobs
GROUP BY tenant_id
ORDER BY running DESC
LIMIT 10;

One tenant with most of the running jobs while others have the oldest waits is starvation in progress. On SQS fair queues, compare ApproximateNumberOfMessagesVisible with ApproximateNumberOfMessagesVisibleInQuietGroups; on Kubernetes, alert on apiserver_flowcontrol_rejected_requests_total by flow_schema and reason.

Sources

The primary sources this guide was checked against.

Hear it discussed

Episodes of the show that work through this decision.