Standalone conceptPatternChapter II · Communication · Building block 11 of 23

Priority Queue

Priority queues shift scarce capacity toward urgent work.

  1. ClassRanks work by business-verifiable urgency.
  2. FairnessSecures capacity or maximum wait for lower classes.
  3. AgeShows starvation despite total throughput.

Context

Why this is important

The central decision concerns fairness under sustained load.

The invoice queue is hypothetical; currently seven modules run together.

Shop example · Mapping

Fairness strategies

The existing shop processes seven modules in a modular monolith. For hypothetical asynchronous invoice generation, legally required corrections are urgent and normal first invoices are regular. Two of ten processing slots remain reserved for regular work; its priority increases after a defined wait. The team generates urgent jobs for an extended period and proves throughput, oldest-message age, and met waiting time for both classes before adopting the rule.

This is how you read the picture

  1. Class Few classes with admission criteria
  2. Fairness Quota or aging
  3. Age Oldest message per class
Fairness strategies
ComparisonStrategyEffectRisk
Strict priorityUrgent always firstLowest urgent latencyStarvation of normal work
Capacity quotaShare per classPredictable minimum progressUnused reservation
AgingPriority rises with timeBounds maximum ageMore complex rule
The strategy determines progress of normal work.

Benefits & limitations

Helps if:

  • Urgent and normal work have different waiting-time objectives.
  • Later processing of normal work remains acceptable.
  • Classes can be assigned by stable rules rather than user preference.

Boundaries

  • Priority does not replace capacity planning; under overload, total backlog grows.
  • Too many classes make rules unclear and encourage arbitrary escalation.
  • Strict priority can starve normal work; its maximum wait needs its own SLO.

In practice

  1. Place urgent correction invoices and routine invoices in separate priority classes. Measure both classes’ waiting time during a sustained urgent workload.
  2. Apply a limit to urgent messages and check whether routine work starts within its agreed deadline. Reserve worker capacity or a separate lane and document the resulting fairness rule for the normal queue.
  3. Compare separate queues with one priority queue. Check fairness, reserved capacity, monitoring, and behavior when a priority value is malformed.
Read the detailed explanation

The sender or broker assigns every message to a business-justified class. Within a class, documented broker ordering applies; between classes, the fairness strategy decides.

Sustained high-priority traffic can displace lower classes. Quotas, aging, or reserved consumers make minimum progress for normal work measurable.

Publish-Subscribe distributes events to independent subscribers. Backpressure limits intake when even prioritized processing cannot carry the load.

Check your understanding

Test yourself in three stages

  1. ReadingCheck in the picture

    Which metric shows starvation?

    View the solution with justification

    The age of the oldest message per class.

  2. ApplyingTransferred to a new situation

    How does the shop protect normal invoices?

    View the solution with justification

    Through reserved slots and aging after a defined wait.

  3. EvaluateWeighing an alternative

    Why does priority not solve capacity shortage?

    View the solution with justification

    It changes only order; total backlog keeps growing.

Continue on the learning path

Next in Communication & APIs: Idempotency.

23 Building blocks

Continue withIdempotency