In Spring WebFlux, Mono<T> is the type for an asynchronous result that contains at most one value. Controllers, services, WebClient calls and reactive repositories return a Mono for a single object, an empty result or a completion signal, and the framework subscribes to it and writes the response without blocking a thread while it waits.
A Mono is part of Project Reactor, implements the Reactive Streams Publisher interface, and is lazy: nothing runs until a subscriber appears.
A Mono ends in exactly one of three ways:
null.That is why Mono<Void> is common for operations such as delete, which only report success or failure.
| Property | What it means in WebFlux |
|---|---|
| Non-blocking | The thread is released while waiting for I/O and resumes when data arrives. |
| Lazy | A pipeline only runs once subscribed, and WebFlux subscribes for you. |
| Backpressure aware | Implements Reactive Streams, so demand flows upstream. |
| Composable | Operators such as map, flatMap, zip and onErrorResume build larger flows. |
| Re-subscribable | Each subscription re-runs a cold source such as a database query. |
get maps a present product to HTTP 200 and substitutes 404 when the Mono is empty. delete returns Mono<Void>, which completes when the deletion finishes.
Use map for a synchronous transformation and flatMap when the next step is itself reactive.
Using map where flatMap is needed produces a nested Mono<Mono<T>>, which is a common beginner mistake.
When two calls do not depend on each other, run them concurrently with zip:
Total latency is roughly the slower of the two calls. If either source is empty, zip completes empty, so add defaultIfEmpty when a missing part is acceptable.
The call fails after two seconds, retries twice with backoff, and finally falls back to a default value. For domain errors, use Mono.error(new NotFoundException(id)) and map exceptions to HTTP statuses in a @ControllerAdvice or with @ResponseStatus.
block() in request-handling code. Reactor throws on a non-blocking thread, and elsewhere it defeats the purpose.Mono.fromCallable(...).subscribeOn(Schedulers.boundedElastic()).Mono that is not returned, chained or subscribed never executes.Mono.just(compute()) for work that must be deferred. Use Mono.fromSupplier or Mono.defer.Similar in shape (zero or one value), but a Mono is asynchronous and lazy, can fail, and supports operators and backpressure.
Return Mono<T> when the default status is fine. Use Mono<ResponseEntity<T>> when you need to control status codes or headers, such as 404 for an empty result.
In production code you do not. You compose with operators and return the Mono. In tests, use StepVerifier or block().
Because empty means "no value" and not an error. Convert it with switchIfEmpty(Mono.error(...)) or defaultIfEmpty to return 404.
Mono is the Reactor type for a single asynchronous result in Spring WebFlux. Return it from controllers and services, compose with map, flatMap and zip, handle absence with defaultIfEmpty or switchIfEmpty, and keep the pipeline free of blocking calls.