Skip to content
← All posts
  • June 29, 2026
  • 7 min read
  • #design-systems

The queue was doing exactly what it was built to do

CPU sat at 70%. The database was fine. One request still waited two and a half minutes for a worker to even notice it existed.

CPU sat at 70%. The database was fine. One request still waited two and a half minutes for a worker to even notice it existed.

Cold open

The page came in at 9:04pm: p99 latency on /checkout had crossed one minute, the alert threshold the team set two flash sales ago. By the time Dara had her laptop open, the dashboard read two minutes forty seconds, and the line was still climbing.

She pulled up the service overview expecting a fire. She got nothing.

CPU across the worker fleet: 71%, comfortably inside the band the team had always called safe. Database query latency: 11ms average, the same as every other Tuesday. Error rate: flat. Throughput was up, but only to about 1.4x normal, the kind of bump two flash sales ago had soaked up without anyone noticing.

Nothing was broken. Something had still made a customer wait two and a half minutes for a page that’s supposed to take half a second.

The instinct that was wrong

Her first theory was the obvious one: the database had quietly run out of connections, or autoscaling had stalled. Both are the usual suspects, and both are usually right.

Neither was right this time. The database graphs hadn’t moved. The autoscaling group had fired on schedule and was already launching new instances. Whatever was eating two and a half minutes wasn’t happening in the database, and it wasn’t because nobody noticed the spike.

She gave up on fleet-level graphs and pulled a trace for one of the slow requests instead. Almost the entire span lived between two timestamps she’d never once put on a dashboard: when the request was enqueued for a worker, and when a worker actually picked it up. Everything after that, the real work, the part the team had spent a year optimizing, took about 50 milliseconds. The team had a metric for how many messages were sitting in the queue. They had never built one for how long the oldest of them had been waiting there.

The real math

A queue with a pool of workers behind it can be described with two numbers: how fast work shows up, and how fast it can get done. Call them λ (arrival rate) and μ (service rate). Their ratio, ρ = λ/μ, is utilization, the same number every dashboard already shows as CPU percent or fleet utilization.

What the dashboard doesn’t show is what that ratio does to wait time. The relationship isn’t a straight line. For a single queue feeding a pool of workers, the standard result from queueing theory says average wait time, as a multiple of how long one task takes to run, comes out to ρ / (1 − ρ).

Wait time, as a multiple of average service time, plotted against utilization. The curve barely moves below 50%, then bends hard.

Run a few values through it and the shape becomes obvious. At 50% utilization, the average wait is about one task’s worth of time. At 70%, it’s 2.3x. At 90%, 9x. At 95%, 19x. Moving from a comfortable utilization to an uncomfortable one doesn’t add a bit more wait. It multiplies it by an order of magnitude, and it does that without utilization ever touching 100%.

Now put Dara’s numbers through it. The worker fleet could handle about 1,000 checkout requests a second combined. Normal flash-sale traffic ran around 700 a second: ρ = 0.7, a 2.3x multiplier on a 50-millisecond task, about 117 milliseconds of wait. Invisible. That’s the comfortable 71% CPU everyone trusted, and for a year and a half, trusting it had been fine.

The burst pushed traffic to about 1,500 a second. New capacity doesn’t appear instantly: Amazon EC2 Auto Scaling’s default cooldown is 300 seconds, and the default instance warmup is another 300 seconds if you haven’t tuned it, so a freshly launched instance can sit for several minutes before it’s actually counted as ready capacity. Call it five minutes, the number most teams never go back and override. For that whole window, the fleet was taking in 500 more requests a second than it could finish.

This is also why throughput looked fine in the cold open. A system can only finish work as fast as it has capacity to finish it, so completed requests per second caps out around 1,000 no matter how many more are arriving. That’s the “1.4x normal” Dara saw on the throughput graph: a number capped by capacity, not driven by demand, so it can’t show you an overload even when one is happening.

Run the arithmetic: 500 extra requests a second for 300 seconds is 150,000 messages stacked up at the worst point. A request landing right then sits behind all of them, and the fleet is still only clearing them at roughly 1,000 a second while it waits for new capacity to count. That’s about 150 seconds, the two minutes thirty Dara watched climb on her screen. This is back-of-envelope math built for one fictional flash sale, not a measured incident, but the mechanism behind it is real: a queue converts a capacity shortfall into elapsed time, and the conversion rate gets worse exactly when you need it to behave.

Three versions of the same queue

Steady load, no bursts. Traffic holds around 70% utilization all day. The queue does what everyone assumes a queue does: smooths out the normal jitter, wait stays under a couple hundred milliseconds, nobody ever thinks about it. This is the case every team has implicitly tested for, because it’s the case that happens most days.

A burst that fits inside the scaling window. This is Dara’s flash sale. Demand exceeds capacity for a few minutes, backlog builds, new capacity arrives, backlog drains. The damage is real but bounded: a subset of requests waited minutes, then it was over. What’s dangerous here isn’t the incident. It’s how easy this is to write off afterward as a one-time fluke, when it was actually a predictable consequence of how long scaling takes.

A burst that outlasts the scaling window. Demand keeps exceeding capacity even after new instances come online, maybe because the spike is bigger than one round of scaling can cover, or because timed-out clients are retrying and adding load on top of the original burst. The backlog never gets a chance to drain. At that point the queue isn’t smoothing anything. It’s just postponing an outage that’s still coming, and waiting for it to resolve itself isn’t a strategy.

What the green dashboard had been hiding

Queue depth and CPU utilization measure the inputs to the wait-time formula. They don’t measure its output, which is the only thing the customer actually experiences: elapsed time. The gap between those two views is small when utilization is low and gets worse exactly as utilization climbs, which means the metric most teams watch is least trustworthy at the moment it matters most.

This isn’t a mistake unique to Dara’s team. Two different ecosystems ran into the same gap and built a fix for it. AWS’s CloudWatch documentation lists a metric called ApproximateAgeOfOldestMessage for SQS queues, reported in seconds, specifically because a message count doesn’t tell you how long anything has actually been waiting. Kafka’s community hit the same wall from the other direction: the standard consumer lag metric counts how many records a consumer is behind, not how much time that backlog represents, and an actual Kafka improvement proposal, KIP-489, was written to add a dedicated latency metric because lag in records and lag in time can tell very different stories for the same backlog. A streaming infrastructure vendor, WarpStream, wrote about the same gap in their own monitoring guidance, making the case that time-based lag is the metric worth alerting on. Three different teams, three different systems, the same blind spot.

The decision guide that came out of it

Dara didn’t rebuild the checkout pipeline. What she added was a metric, and a question the team now asks before trusting any queue.

Instrument time, not just depth:

  • Track time-in-queue directly: timestamp at enqueue, timestamp at dequeue, subtract. For SQS, that’s ApproximateAgeOfOldestMessage. For Kafka, prefer a time-based lag metric over raw record lag if you have one wired up.
  • Alert on the time metric, not the count. A count tells you something is building. A time tells you what it’s costing someone right now.

Treat high utilization as a different regime, not a bigger version of the same one:

  • Below roughly 80% utilization, a few more points of load cost you a little more wait. Above that, the same few points cost you a lot more, because you’re climbing the steep part of the curve.
  • Know your actual scaling reaction time (check your own cooldown and warmup settings, don’t assume the defaults) and size how much queue depth you’re willing to tolerate for exactly that window, not for “however much fits in memory.”

Decide what kind of queue you actually have:

  • A shock absorber smooths a burst and recovers within a bounded time, because demand always comes back down before the backlog becomes unreasonable.
  • A release valve is being asked to absorb more than it can actually handle, so it can only delay the problem, not solve it. If your SLA can’t tolerate the recovery window in the worst case, you need a bounded queue depth plus rejection or load shedding once it’s full, not more patience.