Quick revision
The short answer
An empty 200 means an empty Mono reached the end of the pipeline: WebFlux treats a Mono that completes without a value as a successful response with no body. I would look for where the value disappears, such as a filter that drops it, a missing switchIfEmpty, or an onErrorResume returning Mono.empty() and hiding an error, and check for detached subscribe() calls whose results never reach the response and for errors dropped after cancellation (Hooks.onErrorDropped). To find it, I add log() or doOnNext and doOnSuccess around suspect operators in a test or staging, and reproduce it with StepVerifier using the same inputs.
What to remember
In this answer, we saw that an empty 200 in WebFlux means an empty Mono reached the end of the pipeline, which the framework treats as success. We looked at where values disappear: empty sources without switchIfEmpty, filters, untyped onErrorResume returning Mono.empty(), then() and detached subscribe() calls, and errors dropped after cancellation. We located the responsible operator with log() or doOnSuccess around suspects in a test or staging, reproduced it with StepVerifier, and fixed it with explicit handling for empty and typed error fallbacks.
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.
An empty 200 means an empty Mono reached the end of the pipeline: WebFlux treats a Mono that completes without a value as a successful response with no body. I would look for where the value disappears, such as a filter that drops it, a missing switchIfEmpty, or an onErrorResume returning Mono.empty() and hiding an error, and check for detached subscribe() calls whose results never reach the response and for errors dropped after cancellation (Hooks.onErrorDropped). To find it, I add log() or doOnNext and doOnSuccess around suspect operators in a test or staging, and reproduce it with StepVerifier using the same inputs.
Why this question is asked
A 500 error is easy to investigate: there is a stack trace and usually a log line. An empty 200 is much harder, because from the framework's point of view nothing went wrong. The client gets a success status with no data, no error is logged, and the problem appears only sometimes. This symptom is common in reactive code, and interviewers like it because the investigation requires understanding what empty means in Reactor and where values can silently vanish. In this answer, we will recap how WebFlux turns a Mono into a response, list the places values disappear, see how to locate the one responsible, and reproduce it in a test.
1A Quick Recap: Empty Is a Valid Outcome
A Mono can end in three ways: with one value followed by completion, with an error, or with completion and no value at all. The third, an empty Mono, is a normal, legal result in Reactor, often meaning 'nothing found'. When a controller returns Mono<Order>, WebFlux subscribes to it and writes the response when it finishes. A value becomes the body; an error goes to the exception handlers; and an empty completion is treated as success with no body, so the client sees 200 with an empty response.
So our task is to find which operator turned a value into nothing, or which error was converted into nothing, on the requests that fail. The fact that it happens only sometimes is a clue: something depends on the data, on timing, or on a downstream service's behaviour.
- Repository or client returns a value?YesNext operatorNoEmpty from the start: missing switchIfEmpty
- filter or filterWhen keeps it?YesNext operatorNoDropped: empty Mono
- Error occurred?YesonErrorResume returns Mono.empty()?NoValue reaches the controller
- Controller returns the MonoWebFlux subscribes
- Empty completion200 with no body, no log
5 steps in order. Play them, or step through them one at a time.
2Where Values Disappear
The most common causes fall into a few families. The first is a genuinely empty source with no handling: findById returns empty for an id that does not exist, and the code has no switchIfEmpty to turn it into a 404, so the client sees 200 and nothing. The second is a filter: filter(o -> o.isVisibleTo(user)) drops the value for some users, which explains why it only happens sometimes. The third, and the most dangerous, is an error hidden by a fallback: onErrorResume(e -> Mono.empty()) without an exception type converts every failure, a timeout, a 500 from a dependency, a NullPointerException, into an empty result, with no log line.
The fourth family is structural. A flatMap whose inner publisher is empty yields an empty result. A then() discards the previous value, so a pipeline ending in save(order).then() returns Mono<Void>. And a detached subscribe() inside a method starts work whose result never reaches the response: the method returns something else, often an empty Mono, while the real work runs on its own.
3Locating the Responsible Operator
Reading the code gives us suspects; observing the signals confirms which one it is. In a test or staging environment, we add log() with a category at a few points, or doOnNext, doOnSuccess and doOnError, which are more targeted. doOnSuccess is useful here because it fires on completion of a Mono with the value, or with null when the Mono is empty.
The first log line where the value turns into null names the culprit. If the value is null from the start, the source was empty. If it disappears at onErrorResume, the temporary warn log reveals the hidden error. Production logs can help too: comparing request ids of empty responses with downstream timeouts or errors in the tracing system often shows a pattern, such as empties happening exactly when the pricing service times out.
4Errors Dropped After Cancellation
One more source is subtle. If the client disconnects, or a timeout or take operator cancels the subscription, the pipeline is cancelled. An error that the upstream produces after cancellation has nowhere to go, because nobody is listening any more. Reactor sends it to the onErrorDropped hook, which by default logs it at error level as 'Operator called default onErrorDropped'. If those log lines appear around the same time as the empty responses, the pipeline was likely cancelled, for example by a timeout operator combined with an onErrorResume that turned the timeout into empty, while the real error was dropped. Registering Hooks.onErrorDropped with our own logger, with the trace id, makes these visible.
5Reproducing It With StepVerifier
Once we have a suspect, we reproduce it in a test with the same inputs: the same user, the same order, and the downstream mock returning what it returned in production, for example a delay longer than the timeout.
The fix follows from the cause: switchIfEmpty to turn a legitimate empty into a 404 or a default, typed onErrorResume so only expected errors are handled, returning publishers instead of subscribing to them, and logging inside any fallback that remains. The test stays as a regression test.
6Follow-up questions
How can we make empty results visible in production?
Add a metric or a debug log when an endpoint completes empty, for example with doOnSuccess(v -> { if (v == null) counter.increment(); }). A dashboard of empty responses per endpoint makes a sudden rise obvious, long before a customer reports it.
Is returning 200 with an empty body ever correct?
Rarely for a single resource. For a resource that does not exist, 404 is correct; for an action with no content to return, 204 No Content is clearer. For collections, an empty JSON array with 200 is correct, and a Flux that completes empty gives exactly that.
Why does the problem appear only sometimes?
Because the cause depends on data or timing: a filter that is false for some users, a downstream service that occasionally times out into an untyped fallback, or a race in a detached subscription. Correlating the empty responses with request attributes and downstream errors in traces usually reveals which.
7Conclusion
In this answer, we saw that an empty 200 in WebFlux means an empty Mono reached the end of the pipeline, which the framework treats as success. We looked at where values disappear: empty sources without switchIfEmpty, filters, untyped onErrorResume returning Mono.empty(), then() and detached subscribe() calls, and errors dropped after cancellation. We located the responsible operator with log() or doOnSuccess around suspects in a test or staging, reproduced it with StepVerifier, and fixed it with explicit handling for empty and typed error fallbacks.
Open with
An empty 200 means a Mono completed without a value, and WebFlux treats that as success with no body, so there is no error to log. I would look for where the value vanishes.
Then, if they want more
Typical causes are a source that is legitimately empty, like findById for a missing id, with no switchIfEmpty to turn it into a 404; a filter that drops the value for some inputs, which explains why it is intermittent; and the nasty one, an onErrorResume returning Mono.empty without an exception type, which turns timeouts and downstream 500s into silent empties.
I would also check for then() discarding a value and for detached subscribe calls inside methods, whose results never reach the response, and for errors dropped after cancellation, which show up through Hooks.onErrorDropped as 'Operator called default onErrorDropped' log lines.
To pinpoint it, in a test or staging environment I add log() or doOnSuccess with a debug line after each suspect operator; doOnSuccess shows null when the Mono is empty, so the first null names the culprit. In production I correlate empty responses with downstream errors in traces.
Then I reproduce it with StepVerifier using the same inputs, fix it with switchIfEmpty and typed error handling, keep the test as a regression test, and add a metric for empty completions per endpoint.
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 "A WebFlux endpoint sometimes returns an empty 200 response instead of data, with no...": https://scrivio-interview-library.netlify.app/spring-boot/reactive-testing-and-ops/66b476dd2d/