Skip to content

"A queue makes the system faster"

“The API is slow under load. Put a queue in front of the work and process it asynchronously; the system will be faster.”

A worker processes jobs, such as generating a document, in 50 ms on average, so it can complete about 20 jobs a second. Jobs arrive at random. The team puts a queue in front of it.

To keep the arithmetic exact, assume the simplest standard queueing model: jobs arrive at random, processing times vary at random around the average, and one worker takes jobs in order (an M/M/1 queue). In that model, the average time a job waits in the queue is ρ ÷ (1 − ρ) times the processing time, where ρ is utilization: the share of time the worker is busy.

Arrivals Utilization Average wait in queue Average total time per job
10 jobs/s 50% 50 ms 100 ms
14 jobs/s 70% about 117 ms about 167 ms
16 jobs/s 80% 200 ms 250 ms
18 jobs/s 90% 450 ms 500 ms
19 jobs/s 95% 950 ms 1 second
22 jobs/s over 100% grows without limit grows without limit

The queue didn’t make any job faster: each still takes 50 ms of work. It added waiting. At 90% utilization, a 50 ms job takes ten times as long from submission to completion. And by Little’s law (jobs in the system = arrival rate × time in the system), there are on average 18 × 0.5 = 9 jobs in the system at once.

If arrivals exceed capacity, at 22 jobs a second for instance, the backlog grows by 2 jobs every second: 7,200 jobs an hour. The queue doesn’t fail. It accepts every job and quietly delays all of them, until messages expire, storage fills, or users notice their documents are hours late. A synchronous API would at least have told callers it was overloaded.

A queue in front of one worker1. Jobs arrive at random, so sometimes several arrive together and wait. 2. At 90% utilization, the average job waits nine times as long as it takes to process. 3. Above capacity, the queue grows forever; nothing pushes back on callers. Callers18 jobs/s, at random Queueaverage 9 in system Worker50 ms per job; max 20/s 500 ms per jobat 90% utilization Unbounded backlogat 22 jobs/s123
A queue in front of one worker The queue absorbs bursts and decouples callers, but every job still waits its turn, and waiting grows sharply as the worker approaches full utilization.
  1. Jobs arrive at random, so sometimes several arrive together and wait.
  2. At 90% utilization, the average job waits nine times as long as it takes to process.
  3. Above capacity, the queue grows forever; nothing pushes back on callers.

Change the arrival rate, the processing time and the number of workers. The chart shows the total time per job at every arrival rate, up to the workers’ capacity. The first scenario reproduces the example above.

A queue changes when work happens, not how much capacity there is. It smooths bursts, decouples callers from workers, and lets work survive a worker restart. Those are real benefits. But waiting time depends on utilization in a sharply non-linear way: as a worker approaches 100% busy, the queue in front of it grows rapidly, because random bursts no longer have idle time to drain into.

And a queue hides overload. Without limits, it turns “we’re out of capacity” into “everything is late”, which is often worse, and harder to see.

  • The caller doesn’t need the result immediately: emails, reports, image processing, ledger posting. “Faster” means the caller returns sooner, not that the work finishes sooner.
  • Average demand is below capacity, and the queue only absorbs short bursts.
  • Workers scale with queue depth or age, and there’s enough headroom to keep utilization moderate.
  • The queue has limits: a maximum depth or age, after which new work is rejected or degraded, and alerts on the age of the oldest message.

A queue makes callers faster and the system smoother, not the work faster. Keep utilization well below 100%, scale workers on queue age, cap the queue, and alert on how old the oldest message is.

Discussion question. Your queue depth chart looks flat and healthy, but customers complain that reports arrive hours late. What metric would have shown the problem, and why doesn’t queue depth?

Exercise. Arrivals stay at 18 jobs a second. You add a second identical worker. Using the rule of thumb that two workers behave roughly like one worker twice as fast, estimate utilization and the average total time per job. How does it compare with 500 ms?

Worked answer

Two workers give a capacity of 40 jobs a second, so utilization is 18 ÷ 40 = 45%. Treating the pair as one worker with a 25 ms processing time: average wait ≈ 0.45 ÷ 0.55 × 25 ms ≈ 20 ms, and total time ≈ 45 ms. (The exact model for two workers, M/M/2, gives about 63 ms, because each job still takes 50 ms on whichever worker picks it up.) Either way, a job now takes about 45 to 65 ms instead of 500 ms. Doubling capacity cut the time per job about eightfold, because waiting falls steeply as utilization drops.

Written and edited by Abhinav Taduka, enterprise software architect.