Backpressure: When the Consumer Is Slower Than the Producer
Objectives
By the end of the lesson, you can explain the concept of backpressure, say what happens if the arrival rate persistently exceeds the processing rate, and list the means of defence.
Why is it needed?
A queue buffers, but it does not increase capacity without limit. According to the Azure description, if the average producer rate exceeds the consumer rate, the queue keeps growing, and latency with it. If a system accepts more work without limit than it completes, it only pushes the load into memory or into a durable queue.
What is backpressure?
Backpressure: the slower consumer or processor feeds back on production, delivery or acceptance, and so does not allow the system to accumulate work without limit.
Let λ be the arrival rate and μ the total processing rate. If persistently λ > μ, the waiting work grows; a buffer is useful for a short time, but for sustainable operation the capacity and the load pattern must fit together. More consumers do not speed things up either if all of them wait on the same limited external service. Azure warns: autoscaling without limiting the consumers' aggregate downstream rate only moves the overload onto the downstream dependencies.
flowchart LR
P["Producer (λ)"] --> Q[("Queue / buffer")]
Q --> C["Consumer (μ)"]
C -.->|"slow: feedback"| P
- Consumer limit: the RabbitMQ prefetch value sets how many unacknowledged messages a channel may receive at once. It protects memory and helps even distribution; with too large a value one consumer reserves a lot of work while others are idle. The documentation mentions a value in the 100–300 range as a common good start and 1 as the most conservative; this must be measured in the concrete environment.
- Limit at the entry point: the system can refuse or delay new work if there is no capacity it can commit to. A clear response is needed: accepted and queued, try again later, or the operation cannot be started. The state and expiry of durably accepted work must be shown.
- Merging or dropping: for a current value (for example the latest measured value) several updates can be merged; in a financial transaction an intermediate record cannot be dropped. The "drop old messages" rule can follow only from the meaning of the message.
- Limit of parallelism: if the events of an entity must be applied in order, unlimited parallel processing is not started for the same key; other keys can still proceed at the same time.
- Measurement: besides the queue length, the age of the oldest message, the processing time, the retry rate and the final failure are also important.
Synchronous or asynchronous?
For an immediate decision, such as an authorisation check or the result of a reservation, a direct response is often needed. For long processing and several independent reactions the asynchronous model is advantageous. The price of asynchronous operation is the pending state, the late result, repetition and a process tracked in several places, and the client must also know that the work is still in progress (6.2).
Characteristics
| Aspect |
Asynchronous queue with backpressure |
| Direction |
Producer → consumer; slowness feeds back |
| Initiator |
The producer sends; the consumer takes at its own pace |
| Latency |
Grows with the length of the queue |
| Load |
Buffer; the downstream dependency is protected |
| Fault tolerance |
Absorbs a transient peak; not persistent overload |
| When it fits |
Variable load, protecting a slow dependency |
| When it does not |
If an immediate answer is needed, or persistently λ > μ |
Common misconceptions
| Statement |
Clarification |
| "A queue solves overload." |
It only absorbs the peak; with persistent λ > μ it grows. |
| "More workers are always faster." |
Not if they wait on the same limited dependency. |
| "Watching the queue length is enough." |
The age of the oldest message and the outcome are needed too. |
In short
- Backpressure is the feedback of a slow consumer to production.
- With persistent λ > μ the queue grows; capacity or an input limit must be designed.
- Tools: prefetch, entry limit, merging, per-key parallelism, measurement.
- Asynchronous operation has a pending state, which must also be signalled to the user.
Review questions
- What happens if λ is persistently greater than μ?
- Why does adding workers not help if all of them wait on an external API?
- When may messages be merged or dropped?
Learning resources
Backpressure: When the Consumer Is Slower Than the Producer
Objectives
By the end of the lesson, you can explain the concept of backpressure, say what happens if the arrival rate persistently exceeds the processing rate, and list the means of defence.
Why is it needed?
A queue buffers, but it does not increase capacity without limit. According to the Azure description, if the average producer rate exceeds the consumer rate, the queue keeps growing, and latency with it. If a system accepts more work without limit than it completes, it only pushes the load into memory or into a durable queue.
What is backpressure?
Backpressure: the slower consumer or processor feeds back on production, delivery or acceptance, and so does not allow the system to accumulate work without limit.
Let λ be the arrival rate and μ the total processing rate. If persistently λ > μ, the waiting work grows; a buffer is useful for a short time, but for sustainable operation the capacity and the load pattern must fit together. More consumers do not speed things up either if all of them wait on the same limited external service. Azure warns: autoscaling without limiting the consumers' aggregate downstream rate only moves the overload onto the downstream dependencies.
flowchart LR P["Producer (λ)"] --> Q[("Queue / buffer")] Q --> C["Consumer (μ)"] C -.->|"slow: feedback"| PTools
Synchronous or asynchronous?
For an immediate decision, such as an authorisation check or the result of a reservation, a direct response is often needed. For long processing and several independent reactions the asynchronous model is advantageous. The price of asynchronous operation is the pending state, the late result, repetition and a process tracked in several places, and the client must also know that the work is still in progress (6.2).
Characteristics
Common misconceptions
In short
Review questions
Learning resources