loader.tsx
Back to the Grimoire

VolumeDistributed Systems

Backpressure

JAN MMXXVIFolio I of I

Backpressure

Backpressure refers to situations where data does not flow correctly, causing the system to exhibit issues such as timeouts, growing queues, OOM (out-of-memory) errors, or increased latency.

The most classic example is when one part of the system processes faster than another. Suppose we have three microservices: A, B, and C.

A receives user photos and their data such as name, email, etc. B is responsible for processing them with AI to improve photo quality, and C stores them and sends them by email once they are ready. The problem can arise when A sends B 100 photos per second, but B can only process 50 photos per second. This means we end up with 50 photos in the backlog (they remain queued/pending, or they start failing if there is no queue/buffer or if limits are hit (timeouts, memory, queue size)).

In this scenario, backpressure tactics come into play. Some of the most common are:

Controlling

Basically, a Consumer—in this case B—tells A to send fewer requests, to slow down. This is a good strategy, but it cannot always be implemented.

Buffer

We store in a buffer the data that cannot be processed so it can be processed later. In this strategy, a limiter is usually used because otherwise we can get an OOM (out-of-memory) and crash.

Dropping

We simply drop the data that cannot be processed. There are several criteria: drop the oldest, the newest, or even randomly.