Why priority
Not all messages are equal. A password reset should jump ahead of a nightly report. A priority queue lets higher priority messages be served before lower ones, even if they arrived later.
Common implementations
- Multiple queues by level: one queue per priority, consumers drain high before low.
- Score ordering: a single store ordered by a priority score.
- Weighted fair draw: pull from levels in a weighted ratio so low priority still progresses.
The starvation risk
If consumers always drain high priority first, a steady stream of urgent messages can starve low priority ones forever. Weighted fair scheduling or aging, where waiting raises a message priority over time, prevents permanent starvation.
Trade off
Strict priority gives the lowest latency for urgent work but risks starvation. Weighted fairness sacrifices a little urgent latency to guarantee progress everywhere.
Flow
Key idea
Priority queues serve urgent messages first, but need weighted scheduling or aging so low priority work is never starved.