Mono and Flux are the two publisher types of Project Reactor, the library behind Spring WebFlux. Mono<T> represents an asynchronous sequence of zero or one element, and Flux<T> represents a sequence of zero to many elements. Both are lazy, support backpressure, and let you compose non-blocking work with operators instead of threads and callbacks.
They matter because a blocking application needs roughly one thread per concurrent request, while a reactive pipeline lets a small number of threads serve many requests that spend most of their time waiting for I/O.
Reactive programming models data as streams of events and propagates change through them. On the JVM this is standardised by the Reactive Streams specification, whose four interfaces (Publisher, Subscriber, Subscription, Processor) are also part of the JDK as java.util.concurrent.Flow. Reactor implements Publisher in Mono and Flux.
The key idea is backpressure: a subscriber tells the publisher how many items it can handle with request(n), so a fast producer cannot overwhelm a slow consumer.
Use Mono when the result is a single value, or nothing. Typical cases are loading one entity by id, calling an HTTP endpoint that returns one object, or an operation that only signals completion (Mono<Void>).
An empty Mono completes without emitting a value. This is how a reactive repository reports "not found", so use switchIfEmpty or defaultIfEmpty rather than null checks.
Use Flux for collections, event streams, server-sent events and paged results.
A Flux can be infinite, for example Flux.interval(Duration.ofSeconds(1)), which is why you should never block on it with blockLast() in production code.
| Aspect | Mono<T> | Flux<T> |
|---|---|---|
| Elements | 0 or 1 | 0 to N (possibly unbounded) |
| Plain Java analogue | Optional<T> or CompletableFuture<T> | Stream<T> or Iterable<T> with async delivery |
| Typical use | Find by id, create, update, delete | List, search, streams of events |
| Convert | mono.flux() | flux.collectList() returns Mono<List<T>> |
Nothing happens until something subscribes. Building a pipeline only describes the work.
In Spring WebFlux you do not call subscribe() yourself in controllers. You return the Mono or Flux, and the framework subscribes when it writes the response.
Errors travel down the pipeline as a terminal signal, so try/catch does not work around reactive code. Use operators instead.
Mono.zip runs both sources concurrently and combines the results. For a dependent call use flatMap. Never use block() inside a reactive pipeline on an event-loop thread, because Reactor detects it and throws an IllegalStateException.
Reactive code adds complexity, and it helps most in specific situations:
If your application uses blocking JDBC or blocking libraries, Spring MVC with virtual threads (Java 21 and later) often gives most of the scalability benefit with ordinary, imperative code.
Mono emits at most one element and Flux emits any number. Choose by the cardinality of the result.
Because it is lazy. Without a subscriber, no work starts. In WebFlux return the publisher from the handler, and in tests use StepVerifier or block().
Yes. mono.flux() wraps one element in a Flux, and flux.collectList() or flux.next() produce a Mono.
No. A Mono is lazy, can be re-subscribed, supports backpressure and has a much richer operator set. A CompletableFuture starts immediately and completes once.
Mono is a publisher of zero or one item and Flux is a publisher of zero to many items. Both are lazy and non-blocking and implement Reactive Streams backpressure. Pick the type by result cardinality, compose with operators, never block inside a pipeline, and adopt reactive code mainly when your whole stack can be non-blocking.