← Lessons

quiz vs the machine

Gold1470

Concurrency

Backpressure Strategies

What to do when producers outrun consumers.

5 min read · core · beat Gold to climb

The mismatch problem

When a producer emits faster than a consumer can handle, items pile up. Backpressure strategies decide what to do with the surplus rather than letting memory grow without bound.

The main strategies

  • Buffer stores excess items until the consumer catches up, bounded to avoid blowup.
  • Drop discards new items when the buffer is full.
  • Latest keeps only the most recent item and overwrites older ones.
  • Error signals failure when demand is exceeded.

Buffering trades memory for completeness. Dropping and latest trade completeness for bounded resource use, which suits sensor data where stale readings are worthless.

Combining with demand

These strategies sit on top of the request protocol. Even with demand based flow, an operator may emit eagerly, so you place a backpressure operator to bridge a pushy source to a pull based consumer.

Key idea

Backpressure strategies buffer, drop, keep latest, or error to bound resource use when a producer outpaces its consumer.

Check yourself

Answer to earn rating on the learn ladder.

1. Which strategy keeps only the most recent item?

2. What does the buffer strategy trade away?