← Concepts

阅读中文版本

Queue-Based Load Leveling

Queue-based load leveling inserts a queue between producers and a rate-sensitive service so bursts queue instead of overwhelming it, and the service drains at its own sustainable pace.

architecture

Definition

Queue-based load leveling buffers requests in a queue between callers and a capacity-limited service. Producers complete on enqueue; consumers process at a controlled rate matched to capacity. Spikes become queue depth instead of timeouts and errors, and backpressure surfaces as measurable lag. The trade-off is asynchronous completion and latency proportional to queue length.

Context and scope

Applied to email sending, third-party API calls with rate limits, and background processing behind web endpoints. Pairs with competing consumers for horizontal draining.

Common misconceptions

  • The queue makes the system faster — it makes the system survivable; each request waits its turn, adding latency measured in queue depth
  • Queues absorb any load — unbounded queues convert overload into unbounded latency and memory; bounds and rejection are part of the design
  • The service should drain as fast as possible — pacing to sustainable rates protects downstream limits; racing recreates the overload queues exist to prevent

Anti-patterns

  • Enqueuing synchronously from user requests without a completion model, leaving users with no feedback
  • Leaving the queue unbounded during marketing spikes and watching latency and memory grow together
  • Ignoring queue depth alerts until consumers fall behind by hours and deadlines expire silently

Related concepts

Related examples

Authoritative source

https://learn.microsoft.com/en-us/azure/architecture/patterns/queue-based-load-leveling

What it is

A rate-limited or capacity-fragile service collapses under bursts. The queue is a shock absorber: arrival pattern stops mattering to the service, which sees a smooth drain rate it can sustain.

How it works

Producers enqueue and move on. A fixed or autoscaled consumer pool drains at a configured concurrency. Queue depth becomes the primary health metric — growth predicts saturation minutes ahead. Dead-letter queues capture poison messages so one bad item cannot stall the drain.

When to use it

Calls to third-party APIs with quota, sending email and notifications, and any write path whose value survives asynchrony. Keep interactive flows synchronous unless the business accepts eventual completion.

Pitfalls

Async semantics leak into UX: submissions need job status endpoints and progress surfaces. Poison messages stall strict FIFO drains — set max delivery counts and dead-letter policies. Retrying storm-prone consumers amplify depth; apply backoff and jitter at the consumer.