Patterns

Backpressure

Make a slow consumer push back on its producers, so a queue stays bounded instead of growing until memory or latency runs out.

Backpressure is the signal a slow consumer sends upstream so producers slow down, queue less, or fail fast.

Use it when#

  • Producers can outrun consumers for long stretches, not just bursts.

  • An unbounded queue would make each task wait minutes, which users judge as a failure.

  • You would rather refuse some work now than finish all of it too late.

How it works#

Bound the buffer. When a queue holds its maximum, new tasks are refused, and the producer must decide: retry later, drop the work, or tell the user. With a limit of 10,000 tasks and workers that drain 100 a second, nothing waits more than about 100 seconds.

Other forms are a bounded worker pool, a token the producer must hold to send, and a rate limit at the edge. All of them turn an invisible backlog into a visible refusal.

What it costs#

Someone loses work, so the producer needs a plan for a refusal. A limit set too low refuses work during ordinary bursts. Too high, and it protects nothing. Refusals can trigger retries, which add load, so pair the limit with backoff and with load shedding.

In Quorum#

Drag to pan. Hold Ctrl or Cmd and scroll to zoom.

At 3.00k Users the Simulation solves this Design to Apdex 0.68, p99 431 ms, 28.7% errors and $5.01/s Burn.
WhereSettingValueWhy
App ServerInstance sizemediumMedium, so the App Server is not the limit.
QueueMax length10000Past this many waiting tasks the Queue refuses new ones, so the backlog and the wait have a ceiling.
QueueTasks waiting10000The Queue has already filled to its limit, because the Worker is slower than arrivals, so it refuses new tasks.
WorkerInstance sizesmallSmall. If it is slower than arrivals the Queue fills to its limit and then refuses work.
DatabaseInstance sizemediumMedium. It serves the reads and writes users wait for.

Research this Design needs: Message queues, Background jobs, Message queues, Background jobs.

The Design starts with the Queue already at its limit and the Worker slower than arrivals, so the caption shows the refusals. The Queue card has a max length. Past it, the Queue refuses what its Workers cannot take, and those requests fail as dropped. With no limit, depth grows whenever Workers drain slower than tasks arrive, and a new task waits behind the backlog.

Add Workers or make them bigger to bring depth down. See Capacity, utilization, and queues. The glossary defines backpressure.