Not All Jobs Are Equal
A password reset email matters more than a nightly analytics rollup. A plain queue is first in first out, so an urgent job can wait behind a long backlog. A priority queue lets important work jump ahead.
Two Common Designs
- Multiple queues with one queue per priority level. Workers drain the high queue before touching lower ones.
- Scored single queue where each job carries a priority score and the broker pops the best score first.
Multiple queues are simpler to reason about and easy to monitor per level.
The Starvation Risk
If workers always empty the high queue first, low priority jobs may never run during sustained load. Guard against this:
- Weighted draining so workers take, say, nine high jobs then one low job.
- Aging so a job that waits too long gains priority over time.
Picking Levels
Keep levels few, such as high, default, and low. Too many levels make capacity planning hard and rarely change real behavior.
Key idea
Priority queues serve urgent work first, but you must add weighting or aging so low priority jobs are not starved.