← Lessons

quiz vs the machine

Gold1400

System Design

The Priority Queue Broker

Letting urgent messages jump ahead while keeping lower priority work from starving forever.

4 min read · core · beat Gold to climb

Beyond first in first out

A plain queue is first in first out, so a flood of low value messages can delay an urgent one stuck behind them. A priority queue lets the broker serve higher priority messages first regardless of arrival order.

How brokers implement it

  • Some brokers support a priority field per message and a single queue that always pops the highest priority ready item.
  • Others use multiple queues, one per priority level, and consumers drain the high priority queue before the low one. This is simpler and easier to monitor.

The starvation risk

Strict priority can starve low priority work: if high priority traffic never stops, low priority messages wait forever. Common fixes:

  • Weighted draining so consumers take, say, three high then one low message.
  • Aging, where a message gains priority the longer it waits, eventually guaranteeing service.

Key idea

A priority queue serves urgent messages first but needs weighting or aging so lower priority work is not starved.

Check yourself

Answer to earn rating on the learn ladder.

1. What does a priority queue change about a plain FIFO queue?

2. How can strict priority be made fair to low priority work?