Mono and Flux are the two publisher types of Project Reactor. A Mono<T> emits at most one item (or an error), and a Flux<T> emits zero to many items. Both are lazy, non-blocking and support backpressure, so they are the building blocks of reactive code in Spring WebFlux, Spring Data reactive repositories and WebClient.
Choosing between them is mostly about cardinality: use Mono for "one result or none" and Flux for "a sequence".
Both types implement the Reactive Streams Publisher interface. A publisher does nothing until someone subscribes. Subscribing starts the flow of signals: onNext for each item, then either onComplete or onError. The subscriber also signals demand with request(n), which is what backpressure means: the producer must not send more than the consumer asked for.
Because nothing happens before subscribe(), a pipeline is a description of work, not the work itself. In a web application, the framework subscribes for you when it writes the response.
Use Mono when the result is a single value, for example loading one user by id, saving an entity or completing a task with no value (Mono<Void>).
Common factories are Mono.just, Mono.empty, Mono.error, Mono.fromCallable, Mono.fromSupplier and Mono.defer. Use Mono.just only for values you already have; pass computations through fromSupplier or defer so they run on subscribe.
Use Flux for collections, event streams, server-sent events or database result sets that may contain many rows.
Useful factories include Flux.just, Flux.fromIterable, Flux.range, Flux.interval (a timer-driven, possibly infinite stream) and Flux.create for bridging callback APIs.
| Aspect | Mono<T> | Flux<T> |
|---|---|---|
| Items emitted | 0 or 1 | 0 to N, possibly unbounded |
| Typical use | Single entity, save, delete, HTTP response | Lists, streams, events, SSE |
| Blocking equivalent | Optional<T> or CompletableFuture<T> | Stream<T> or List<T> |
| Collect to a single value | Already single | collectList() returns Mono<List<T>> |
You can convert between them. flux.next() and flux.single() give a Mono, mono.flux() gives a Flux, and Mono.flatMapMany turns one value into a sequence.
The most important operators are shared by both types:
map transforms each item synchronously.flatMap transforms each item into another publisher and merges the results, which is how you call async services per item.zip pairs results from several publishers, for example Mono.zip(userMono, ordersMono).concatWith and merge join streams in order or as they arrive.onErrorResume, onErrorReturn and retryWhen handle failures.Both calls start on subscribe and run concurrently when they are truly non-blocking.
A controller returns the types directly and the framework subscribes:
A Flux returned with the text/event-stream media type is sent as server-sent events.
block() inside a reactive pipeline on an event-loop thread. Reactor throws an error for this on non-blocking threads, and it defeats the model anyway.map. Move it to Schedulers.boundedElastic() with subscribeOn, or use a non-blocking client.Mono emits at most one element and Flux emits many. Both complete or fail with a signal and both are lazy.
It is similar in cardinality, but Mono is lazy, composable with a rich operator set, and supports cancellation and backpressure-aware pipelines. A CompletableFuture starts eagerly.
In reactive code, keep chaining operators. In tests or main methods, use block() or StepVerifier from reactor-test.
Use Flux<T> to stream items as they are produced. Use Mono<List<T>> when the client needs a single JSON array response.
Mono represents zero or one result and Flux represents a stream of zero to many. Both are lazy publishers with backpressure and are the core types in Spring WebFlux. Pick by cardinality, compose with operators such as map, flatMap and zip, never block inside the pipeline, and weigh them against virtual threads for simpler workloads.