Most jobs take 300 ms, but a few reports take 30 seconds, and they share a queue and three consumers. Users complain that simple actions sometimes hang. Why, and what do you change?
Sketch your own answer first, then compare it with the one below.
A strong answer
This is head-of-line blocking. When a few report jobs arrive together, they can hold all three consumers for 30 seconds. Every quick job that arrives in that window waits, though it needs a third of a second.
The mean hides it. With 1 report in 100, mean service time is about 0.6 seconds, which looks fine. The 99th percentile of wait is where the pain is.
The cheapest change is separate queues with separate consumers: two for quick work, one for reports. A burst of reports now delays only other reports. The price is some idle capacity, since a spare report consumer cannot help the quick queue.
Priorities inside one queue are the other route, but they only order the waiting line. They do not interrupt a job already running, so a 30 second job still occupies its consumer. They also risk starving low-priority work unless you reserve some share for it.
Sources
- Jeffrey Dean, Luiz André Barroso (2013). The Tail at Scale.
- RabbitMQ documentation (2024). Priority Queues.