Quick revision
The short answer
Backpressure is the way a Reactor subscriber tells its producer how many items it can take, by calling request(n), so that the producer never sends more than was asked for. Flux.interval cannot slow down because it is driven by a clock, so when a tick is due and no demand is left it fails the stream with an OverflowException. We handle that with an explicit strategy such as onBackpressureDrop, onBackpressureLatest or a bounded onBackpressureBuffer, and we shape demand with limitRate(n).
What to remember
In this answer, we saw that backpressure in Reactor is demand counting: the subscriber calls request(n) and the publisher may send at most n items. Pull-based sources like Flux.range and database cursors honour that naturally. Flux.interval is driven by a clock, so when demand reaches zero it fails with an OverflowException rather than quietly piling up ticks. We fix that by choosing an overflow strategy right after the source, drop, latest or a bounded buffer with an overflow policy, and we use limitRate to make large or unbounded downstream demand arrive upstream in manageable batches.
Your turn
Answer it aloud as you would in the interview, or type your answer below. Then show one part at a time and compare.
Backpressure is the way a Reactor subscriber tells its producer how many items it can take, by calling request(n), so that the producer never sends more than was asked for. Flux.interval cannot slow down because it is driven by a clock, so when a tick is due and no demand is left it fails the stream with an OverflowException. We handle that with an explicit strategy such as onBackpressureDrop, onBackpressureLatest or a bounded onBackpressureBuffer, and we shape demand with limitRate(n).
Why this question is asked
Every streaming system has a fast part and a slow part. A database cursor can produce rows faster than we can call another service for each of them, and a timer can tick faster than we can write to disk. If nothing connects the two speeds, items pile up in memory until the process dies. Interviewers ask about backpressure because it is the core promise of Reactive Streams, and because Flux.interval is the classic case where that promise cannot be kept. In this answer, we will recap how demand works, see why pull-based sources behave well, reproduce the interval failure, go through the overflow strategies, and see how limitRate shapes the requests that go upstream.
1A Quick Recap of Demand in Reactive Streams
Reactor implements the Reactive Streams specification, a small contract between a Publisher, which produces items, and a Subscriber, which consumes them. When a subscriber subscribes, the publisher hands it a Subscription object. Nothing flows yet. The subscriber must call subscription.request(n) to say it is ready for n more items, and the publisher may then call onNext at most n times before it waits for the next request.
That counting is what we call backpressure: the consumer pushes back on the producer by controlling demand. It is not a buffer and not a rate limit. It is a running total of how many items the subscriber still wants. When we write flux.subscribe(x -> ...), Reactor requests Long.MAX_VALUE, which means unbounded, so the producer may go as fast as it likes. Most operators in between, such as publishOn, flatMap and concatMap, request in smaller batches (often 32 or 256) and refill as they drain their internal queues, so demand from a slow consumer really travels back to the source.
2Pull-Based Sources Respect Demand Naturally
Some sources produce an item only when asked. Flux.range is the simplest: it holds a counter and emits exactly as many numbers as were requested, then stops and waits. A database cursor read through R2DBC behaves the same way when the driver supports it, fetching the next rows only when demand arrives.
Notice that range never runs ahead. However slow the subscriber is, at most ten numbers exist at any moment. This is the ideal case, and it is why pull-based sources rarely cause memory problems.
3Why Flux.interval Cannot Slow Down
Flux.interval(Duration) is different. It emits 0, 1, 2 and so on, one per period, on a timer thread from Schedulers.parallel(). Time does not wait for anyone, so the operator cannot pause the clock until demand arrives. When a tick is due and the outstanding demand is zero, interval has two bad choices: queue the tick, which hides an unbounded memory leak, or fail. Reactor chooses to fail loudly.
7 messages in order. Play them, or step through them one at a time.
Demand is refilled once per 100 ms but used once per 10 ms, so it reaches zero.
concatMap requests a first batch of items (32 by default in recent versions; check your version) and then one more each time an inner Mono completes. The ticks arrive ten times faster than the inner work finishes, so the batch is used up after about a third of a second, demand reaches zero, and the next tick has nowhere to go. The exact tick number in the message depends on the prefetch, but the outcome is always the same: the stream terminates with an error, and the subscriber sees onError.
So the question to ask about any time-based or push-based source is not whether it supports backpressure, but what it should do when demand runs out. The answer is a choice we make with an overflow operator placed right after the source.
4Choosing an Overflow Strategy
Reactor offers three operators that sit between a source that cannot slow down and a consumer that cannot keep up. Each one answers the question of what to do with an item when there is no demand for it.
onBackpressureDrop discards items that arrive without demand, optionally passing each one to a callback so we can count or log it. It fits data where only fresh values matter and gaps are acceptable, such as metrics samples. onBackpressureLatest keeps only the newest item and delivers it as soon as demand returns, which suits status or price updates where the latest value replaces all older ones. onBackpressureBuffer keeps items in a queue until demand arrives. Without a size, that queue is unbounded, which only moves the memory problem somewhere else, so we always give it a maximum and say what happens when it is full.
| Operator | When demand is zero | Good fit |
|---|---|---|
onBackpressureDrop() | discards the new item | samples where gaps are fine |
onBackpressureLatest() | keeps only the newest item | status or price updates |
onBackpressureBuffer(n, strategy) | queues up to n, then drops or errors | short bursts with a known peak |
onBackpressureBuffer() | queues without limit | almost never: hides a memory leak |
| none | OverflowException | when an error is the right signal |
Notice that the buffer does not make the consumer faster. It absorbs bursts, and when the burst is longer than the buffer we still lose data, but now we lose it in a way we chose and can measure.
5Shaping Demand With limitRate
limitRate(n) does not slow anything down by itself. It changes how the downstream demand is passed upstream. Even if the subscriber requests Long.MAX_VALUE, limitRate asks its source for n items at a time and refills when 75 percent of a batch has been delivered. The variant limitRate(highTide, lowTide) lets us choose both the batch size and the refill point.
This matters for sources that do real work per request. A database driver that fetches rows in batches, or a client that pulls messages from a broker, will fetch in chunks of n instead of trying to load everything because one subscriber said unbounded. So limitRate is the tool for keeping a pull-based source honest; the overflow operators are the tools for sources that cannot be pulled.
6Follow-up questions
Does subscribe() with a lambda support backpressure?
It requests Long.MAX_VALUE, so it declares unbounded demand and never pushes back. The operators in the chain may still request in batches from their own sources, but the final subscriber itself never limits anything. To control demand by hand we extend BaseSubscriber and call request(n) ourselves, or we rely on operators such as limitRate, publishOn and concatMap.
Is onBackpressureBuffer() without arguments ever safe?
Only when we know the total number of items is small and finite, so the buffer has a natural upper bound. For an endless or bursty source it is an unbounded queue, and under a slow consumer it grows until the JVM runs out of heap. A bounded buffer with an explicit overflow strategy is almost always the better choice.
How is backpressure different from a rate limiter?
Backpressure is driven by the consumer's capacity: the producer sends as fast as demand allows, and that can be very fast when the consumer is quick. A rate limiter caps throughput at a fixed number per second regardless of what the consumer could handle. We sometimes use both, for example a rate limiter to respect a partner API's quota and backpressure to protect our own memory.
7Conclusion
In this answer, we saw that backpressure in Reactor is demand counting: the subscriber calls request(n) and the publisher may send at most n items. Pull-based sources like Flux.range and database cursors honour that naturally. Flux.interval is driven by a clock, so when demand reaches zero it fails with an OverflowException rather than quietly piling up ticks. We fix that by choosing an overflow strategy right after the source, drop, latest or a bounded buffer with an overflow policy, and we use limitRate to make large or unbounded downstream demand arrive upstream in manageable batches.
Open with
Backpressure in Reactor means the subscriber controls the flow by signalling demand. It calls request(n) on its subscription, and the publisher is allowed to send at most n items before it has to wait for more demand.
Then, if they want more
Pull-based sources like Flux.range or an R2DBC cursor respect that naturally, because they only produce when asked, so a slow consumer just means the source waits. Flux.interval is the tricky case because it is driven by a timer and cannot pause the clock.
If a tick is due and there is no outstanding demand, for example because a concatMap downstream takes 100 milliseconds per item while ticks come every 10, interval terminates the stream with an OverflowException saying it could not emit the tick due to lack of requests. Reactor fails loudly instead of buffering silently.
The fix is to decide what should happen to the extra items, right after the source. onBackpressureDrop throws them away, which suits samples. onBackpressureLatest keeps only the newest, which suits status updates. onBackpressureBuffer queues them, and I always give it a maximum size and an overflow strategy such as DROP_OLDEST, plus a counter for what was dropped, because an unbounded buffer just turns the error into an out-of-memory later.
Separately, limitRate(n) controls how demand travels upstream: even if my subscriber requests unbounded, the source is asked for n items at a time and refilled at 75 percent, which keeps database or broker fetches in sensible batches.
About this answer
- Last updated
- 12 November 2026
- Checked
- Its structure and format are checked automatically. Use it as a carefully prepared study note: where a detail matters, confirm it against the documentation below. What the checks cover
- Where the question comes from
- Written by Scrivio for practice. It is not taken from an interview.
- Official documentation
- Spring Framework reference, Spring WebFlux, Project Reactor reference guide
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 backpressure in Reactor and what happens when a producer like Flux.interval...": https://scrivio-interview-library.netlify.app/spring-boot/reactive-fundamentals/f9ead7894a/