Scrivio Interview library
ConceptFoundations7 min read · updated 12 November 2026

What is back-pressure, and how do Project Reactor and a blocking ThreadPoolExecutor each handle a producer that is faster than its consumer?

Back-pressure is a way for a slow consumer to limit how fast work reaches it, so memory and latency stay bounded. In Project Reactor the subscriber signals demand with request(n), and operators such as limitRate, a bounded onBackpressureBuffer or onBackpressureDrop decide what happens to overflow. A ThreadPoolExecutor achieves the same with a bounded queue and a rejection policy, where CallerRunsPolicy slows the producer by running the task in its own thread.

Why this question is asked

Almost every system has a part that produces work faster than another part can handle it: a Kafka listener faster than the database, an HTTP client faster than a downstream API, a file reader faster than a parser. If nothing pushes back, the difference piles up in memory until latency explodes or the JVM dies with OutOfMemoryError. Interviewers ask about back-pressure to see whether we know that every queue needs a limit and a plan for when it is full. In this answer, we will define back-pressure, see how Reactive Streams expresses demand, look at the Reactor operators that handle overflow, then do the same for a ThreadPoolExecutor, and finish with how to choose between waiting, dropping and failing.

1A Quick Recap: Fast Producer, Slow Consumer

Imagine a producer that creates 10,000 items per second and a consumer that processes 2,000 per second. Every second, 8,000 items have nowhere to go. They must be stored somewhere, usually in a queue in memory. After one minute that queue holds 480,000 items; if each is a 2 KB object, that is close to 1 GB of heap, and every item at the back waits minutes before it is processed.

Back-pressure is the mechanism that lets the consumer say "slow down" to the producer, so the queue between them stays small and bounded. There are only a few things a system can do when the consumer falls behind: make the producer wait, buffer up to a limit, drop some items, or fail fast. Back-pressure means choosing one of these on purpose instead of letting an unbounded buffer choose for us.

2How Reactive Streams Signals Demand

Project Reactor implements the Reactive Streams specification, a small contract between a Publisher and a Subscriber. The key idea is that data does not flow until the subscriber asks for it. The subscriber calls request(n) on its Subscription to say "I can take n more items", and the publisher may send at most that many. When the subscriber has processed them, it requests more. Demand flows upstream, data flows downstream.

Java
Flux.range(1, 1_000)
.doOnRequest(n -> System.out.println("requested " + n))
.subscribe(new BaseSubscriber<Integer>() {
@Override protected void hookOnSubscribe(Subscription s) {
request(2); // requested 2
}
@Override protected void hookOnNext(Integer v) {
System.out.println("got " + v); // got 1, then got 2, ...
request(1); // requested 1, each time one is done
}
});
Step throughDemand travels up, data travels down
SubscriberFlux
request(2)
onNext(1)
onNext(2)
request(1)
onNext(3)

5 messages in order. Play them, or step through them one at a time.

The publisher sends only what was requested.

Notice that the publisher never runs ahead of the subscriber here. A plain subscribe(consumer) call requests Long.MAX_VALUE, which means "unbounded", so when we care about back-pressure we either write a subscriber like this one or put an operator in the chain that limits the requests for us.

3Reactor Operators for Overflow

Some sources cannot be slowed down, such as UI events, a hot stream of ticks, or messages pushed to us by a socket. For those, Reactor provides operators that decide what happens to items that arrive without demand. limitRate(n) changes the request pattern: instead of passing a huge request upstream, it requests n items, then replenishes in smaller chunks (75 percent of n by default) as they are consumed, which keeps upstream from flooding us.

Java
Flux<Event> events = hotSource();
events.limitRate(100) // ask upstream for 100, then about 75 at a time
.publishOn(Schedulers.boundedElastic())
.subscribe(this::save);
events.onBackpressureBuffer(10_000, // keep at most 10,000 waiting items
dropped -> log.warn("overflow {}", dropped.id()),
BufferOverflowStrategy.DROP_OLDEST) // when full, discard the oldest
.subscribe(this::save);
events.onBackpressureDrop(e -> metrics.increment("dropped")) // no buffer: drop when there is no demand
.subscribe(this::save);

The bounded onBackpressureBuffer is the important one. Without a size, onBackpressureBuffer() is unbounded and only moves the memory problem into the operator. With a bound, we decide what happens when it is full: signal an error (the default), drop the newest, or drop the oldest. onBackpressureDrop keeps no buffer at all and suits data where the latest value matters more than every value, such as sensor readings. There is also onBackpressureLatest, which keeps only the most recent item.

4A ThreadPoolExecutor: Bounded Queue and Rejection Policy

Blocking code has no request(n) signal. A ThreadPoolExecutor takes tasks with execute() and runs them on a fixed number of threads; tasks that cannot start yet wait in its work queue. Back-pressure here comes from two settings: the queue's capacity and the RejectedExecutionHandler, which runs when both the threads and the queue are full.

Java
ThreadPoolExecutor pool = new ThreadPoolExecutor(
4, 4, // 4 worker threads
0L, TimeUnit.MILLISECONDS,
new ArrayBlockingQueue<>(100), // at most 100 tasks waiting
new ThreadPoolExecutor.CallerRunsPolicy());
for (Order o : hugeStream) {
pool.execute(() -> process(o)); // 105th pending task: runs in this loop's own thread
}

With CallerRunsPolicy, when 4 tasks are running and 100 are waiting, the next task runs in the thread that called execute(). While that thread is busy processing the task, it cannot submit more, so the producer slows down to the consumer's speed. That is back-pressure without any extra code. The other built-in policies are AbortPolicy (the default, which throws RejectedExecutionException, so the producer must handle the failure), DiscardPolicy (silently drops the task) and DiscardOldestPolicy (drops the oldest queued task and retries).

But there is a catch: Executors.newFixedThreadPool(4) uses a LinkedBlockingQueue with no capacity limit. Rejection never happens, so the producer is never slowed, and the queue simply grows. With a fast producer this ends in OutOfMemoryError, often after hours of slowly rising latency. An unbounded queue removes back-pressure entirely, which is why production code should build the executor explicitly with a bounded queue.

5Choosing to Wait, Drop or Fail

Both libraries make us choose the same thing: what happens when the consumer is full. The right answer depends on the data, not on the library.

Handling overflow in both worlds
ChoiceProject ReactorThreadPoolExecutor
Slow the producerrequest(n), limitRateCallerRunsPolicy
Buffer up to a limitonBackpressureBuffer(max, ...)ArrayBlockingQueue(capacity)
Drop itemsonBackpressureDrop, DROP_OLDESTDiscardPolicy, DiscardOldestPolicy
Fail fastbuffer overflow errorAbortPolicy (RejectedExecutionException)
No back-pressure (avoid)unbounded onBackpressureBuffer()unbounded LinkedBlockingQueue

For orders or payments, losing work is not acceptable, so we make the producer wait (request(n) in Reactor, CallerRunsPolicy or a blocking put in the executor world) or fail fast with an error the caller can retry. For metrics, previews or position updates, dropping old items is fine and keeps the system responsive. Whatever we pick, we count it: a metric for queue size, rejected tasks and dropped items tells us when the consumer needs more capacity.

6Follow-up questions

Does CallerRunsPolicy have any downside?

Yes. The task runs in the caller's thread, so if the caller is, for example, a Kafka listener thread or a Tomcat request thread, that thread is now busy with work it was not meant to do, and its own duties wait. In a web server it can also mean a request thread runs a slow background task and the user waits. It works best when the producer is a dedicated loop whose only job is to feed the pool.

Is a Semaphore another way to apply back-pressure?

Yes. A Semaphore with, say, 50 permits limits how many tasks are in flight; the producer calls acquire() before submitting and the task calls release() when done. When all permits are taken, the producer blocks. It is useful when we want to limit concurrent calls to a downstream service regardless of which executor runs them. With virtual threads in Java 21 and later this is the usual way to bound concurrency, because creating threads no longer limits it.

7Conclusion

In this answer, we saw that back-pressure is how a consumer limits incoming work so that memory and latency stay bounded. Reactor does it with demand signals, request(n), and operators like limitRate, a bounded onBackpressureBuffer and onBackpressureDrop. A ThreadPoolExecutor does it with a bounded queue and a rejection policy, where CallerRunsPolicy slows the producer. In both, an unbounded queue removes back-pressure and leads to OutOfMemoryError, so we choose explicitly whether to wait, drop or fail when the consumer is full.

What to say in the interviewAbout 90 seconds aloud

Open with

Back-pressure is how a slow consumer stops a fast producer from overwhelming it, so the amount of work waiting in memory stays bounded and latency stays predictable. If the producer makes 10,000 items a second and the consumer handles 2,000, something has to give: we wait, buffer up to a limit, drop, or fail.

Then, if they want more

In Project Reactor, the Reactive Streams contract builds this in. The subscriber calls request(n) and the publisher may only send that many, so demand flows upstream.

For sources that cannot be slowed down, Reactor has operators: limitRate to keep requests small, onBackpressureBuffer with a maximum size and an overflow strategy like drop oldest, or onBackpressureDrop and onBackpressureLatest when only recent values matter. With a classic ThreadPoolExecutor there are no demand signals, so back-pressure comes from a bounded queue such as an ArrayBlockingQueue and a rejection policy.

AbortPolicy throws, the discard policies drop, and CallerRunsPolicy runs the task in the submitting thread, which naturally slows the producer to the pool's speed. The trap I always point out is that Executors.newFixedThreadPool uses an unbounded LinkedBlockingQueue, and an unbounded onBackpressureBuffer is the same mistake in Reactor: there is no back-pressure at all and you eventually get OutOfMemoryError.

So I build executors explicitly, choose deliberately between waiting, dropping and failing based on whether the data can be lost, and put metrics on queue size and rejections.

About this answer

Last updated
12 November 2026
Versions it names
Java 21
Checked
Its structure and format are checked automatically. Use it as a carefully prepared study note: where a detail matters, confirm it against the official documentation for the version you use. What the checks cover
Where the question comes from
Written by Scrivio for practice. It is not taken from an interview.
Report an issue with this answer

Copy the line below and send it to the author with what you found. It carries the address of this page.

Issue with "What is back-pressure, and how do Project Reactor and a blocking ThreadPoolExecutor each...": https://scrivio-interview-library.netlify.app/spring-boot/scalability/908d98b978/