Stackbook Logo
messagingestablished · medium operational burden

Priority Queue

Also known as: priority messaging, multi-lane queue

Intent

Ensure urgent messages are processed ahead of less important ones, without starving the low-priority work completely.

Problem

In a single FIFO queue, a flood of bulk jobs delays time-critical ones. Latency-sensitive work such as password resets waits behind nightly report generation.

Forces

  • •Different messages have different urgency
  • •Low priority work must still eventually complete
  • •Broker support for priorities varies
  • •Strict priority can starve lanes

Solution

Overview

A priority queue prevents head-of-line blocking by importance. The robust implementation is separate queues, since in-queue priority flags are weakly supported and hard to observe.

Good policy matters as much as mechanics: decide who may publish at each level and what that level promises.

Broker-native priority support exists in some systems, but with caveats. Priorities are often honored only among messages currently in memory or on a single node, and large backlogs can behave unexpectedly. Separate queues give isolated metrics, separate scaling and clear failure domains, which is why many teams prefer them.

How it works

Workers poll lanes by weight. Each cycle takes more from high lanes but always visits low ones, so progress is guaranteed.

lanes  = {high: 6, normal: 3, low: 1}   # polls per cycle
for lane, n in lanes.items():
    for _ in range(n):
        msg = queue[lane].poll()
        if msg: handle(msg)

Policy deserves as much attention as mechanics. Define what each lane promises, for example high means processed within five seconds at the 99th percentile, and who is allowed to publish there. Rate-limit the top lane so a bug cannot flood it. Also consider reserving a fixed worker slice for high priority so it never waits for capacity to scale up.

Pitfalls

  • Strict priority with no minimum share, starving bulk work indefinitely.
  • No governance, leading to priority inflation.
  • Too many levels that nobody can reason about.
  • Autoscaling on total depth, which hides a stuck high lane.

Key takeaways

  • Use separate queues for visibility and isolation.
  • Guarantee low lanes a minimum share.
  • Govern who may use top priority.
  • Alert on age of oldest message per lane.

✓ When to Use

  • •Mixed interactive and batch workloads share a pipeline
  • •SLAs differ by customer tier or message type
  • •Bursts of bulk work must not delay critical jobs

✗ When Not to Use

  • •All messages have similar urgency
  • •Strict global fairness is required
  • •Enough capacity exists to process everything promptly

Pros

  • +Protects latency for critical work
  • +Capacity can be reserved per lane
  • +Low priority still progresses with weighting

Cons

  • −Starvation risk with strict priority
  • −Priority inflation as teams label everything urgent
  • −Per-lane tuning adds operations work

Cost Profile

Infrastructure

Medium - multiple queues or pools

Operational

Medium - per-lane scaling and alerts

Cognitive

Low - easy to grasp

Failure Modes

  • Low priority lane starves under constant high-priority load

  • Everyone marks messages high, erasing the distinction

  • Broker priority feature reorders unpredictably under load

Real-World Examples

Alternatives

    Related Patterns

    • competing-consumers
    • dead-letter-queue

    Competency Domains

    distribution communicationeconomics evolution