Quick revision
The short answer
Reactive Streams defines four interfaces: Publisher, which produces items; Subscriber, which consumes them; Subscription, the link between one publisher and one subscriber through which demand is requested and cancellation is signalled; and Processor, which is both a Subscriber and a Publisher. The order is fixed: subscribe() leads to onSubscribe(subscription), the subscriber calls request(n), the publisher sends at most n onNext signals, and the stream may end with exactly one onComplete or onError. Signals to a subscriber must never be concurrent, and the same interfaces exist in the JDK as java.util.concurrent.Flow, with adapters in Reactor.
What to remember
In this answer, we saw that Reactive Streams defines Publisher, Subscriber, Subscription and Processor, which is both a Subscriber and a Publisher. Subscribing leads to onSubscribe with a Subscription, the subscriber signals demand with request(n), the publisher sends at most n onNext signals and then optionally one onComplete or onError, and all signals to a subscriber are serialized. The JDK contains the same interfaces in java.util.concurrent.Flow since Java 9, and Reactor offers adapters between the two.
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.
Reactive Streams defines four interfaces: Publisher, which produces items; Subscriber, which consumes them; Subscription, the link between one publisher and one subscriber through which demand is requested and cancellation is signalled; and Processor, which is both a Subscriber and a Publisher. The order is fixed: subscribe() leads to onSubscribe(subscription), the subscriber calls request(n), the publisher sends at most n onNext signals, and the stream may end with exactly one onComplete or onError. Signals to a subscriber must never be concurrent, and the same interfaces exist in the JDK as java.util.concurrent.Flow, with adapters in Reactor.
Background to this question
Reactor, RxJava, R2DBC drivers, the MongoDB reactive driver and Spring WebFlux all speak a small common language called Reactive Streams. Most of the time we use Mono and Flux and never touch these interfaces directly, but every operator we call follows their rules, and bugs such as lost backpressure or hung streams make sense only once we know them. In this answer, we will look at the problem the specification solves, go through the four interfaces, follow the exact order of signals with a runnable example, and see how the JDK's Flow relates to it.
1The Problem Reactive Streams Solves
Asynchronous code often has a fast producer and a slower consumer, for example a database cursor emitting rows faster than an HTTP client can receive them. If the producer simply pushes everything, the consumer must buffer without limit and eventually runs out of memory. If the consumer blocks a thread while it waits, we lose the point of asynchronous code.
Reactive Streams solves this with backpressure: the consumer tells the producer how many items it is ready for, and the producer never sends more. The specification is tiny, four interfaces and a set of numbered rules, and its goal is interoperability, so that a publisher from one library can feed a subscriber from another.
2The Four Interfaces
A Publisher has one method, subscribe(Subscriber). A Subscriber has four callbacks: onSubscribe(Subscription), onNext(T), onError(Throwable) and onComplete(). A Subscription has two methods, request(long n) and cancel(). A Processor<T, R> extends both Subscriber<T> and Publisher<R>, so it sits in the middle of a chain, consuming one stream and producing another.
Notice where the control sits. The publisher never pushes on its own initiative; it waits for request(n). And the Subscription is per subscriber: two subscribers to the same publisher each get their own Subscription and their own demand.
3The Order of Signals
Every interaction follows the same sequence. First, someone calls publisher.subscribe(subscriber). The publisher must then call subscriber.onSubscribe(subscription) before any other signal. Nothing flows yet. The subscriber calls subscription.request(n) when it is ready, and the publisher may send up to n onNext signals in total across all requests so far. The subscriber can call request again at any time to add demand. Finally the publisher may send one terminal signal, either onComplete for a normal end or onError for a failure, and after it no further signals are allowed. A stream may also never end, as with a ticker.
8 messages in order. Play them, or step through them one at a time.
The publisher never sends more onNext signals than the total requested.
Notice that the publisher sent only two items until the subscriber asked for more. That is backpressure in its simplest form. Reactor's BaseSubscriber is a convenient base class that already follows the rules for us.
4Serialized Signals
One more rule is easy to miss: signals to a single subscriber must be serialized. That means they never overlap in time; onNext for item 2 may come from a different thread than item 1, but it cannot start until onNext for item 1 has returned, and onComplete cannot race with the last onNext. The rule exists so that a subscriber can keep simple state, such as a counter or a buffer, without locks. Publishers that emit from several threads must therefore coordinate before calling the subscriber, which Reactor's operators and sinks do for us.
5Reactive Streams in the JDK: java.util.concurrent.Flow
Java 9 added java.util.concurrent.Flow, which contains the same four interfaces as nested types, Flow.Publisher, Flow.Subscriber, Flow.Subscription and Flow.Processor, with the same rules. The JDK's own HTTP client uses them for request and response bodies, and SubmissionPublisher is a ready-made Flow.Publisher.
Because the org.reactivestreams interfaces and the Flow interfaces are different Java types, an adapter is needed to connect them. Reactor provides JdkFlowAdapter to turn a Flow.Publisher into a Flux and back, and the reactive-streams library itself offers FlowAdapters. Reactor's own Flux and Mono implement org.reactivestreams.Publisher.
6Follow-up questions
What does request(Long.MAX_VALUE) mean?
It means unbounded demand: the subscriber is saying it will accept everything the publisher has, so the publisher may stop tracking demand and simply push. The specification treats a total demand of Long.MAX_VALUE as effectively unbounded. In Reactor, calling subscribe() with only a lambda requests Long.MAX_VALUE, which is why log() shows request(unbounded). It is fine when the consumer is fast and synchronous, but it switches off backpressure, so with a slow consumer the items must be buffered or dropped somewhere else.
Can a publisher call onNext before onSubscribe?
No. onSubscribe must be the first signal, because the subscriber needs the Subscription to request items and to cancel. A publisher that sends onNext first breaks the contract and most subscribers will misbehave.
What happens after cancel()?
The publisher should stop sending signals as soon as it can, release resources such as connections, and drop its reference to the subscriber. A few onNext signals that were already in flight may still arrive, which subscribers must tolerate.
7Conclusion
In this answer, we saw that Reactive Streams defines Publisher, Subscriber, Subscription and Processor, which is both a Subscriber and a Publisher. Subscribing leads to onSubscribe with a Subscription, the subscriber signals demand with request(n), the publisher sends at most n onNext signals and then optionally one onComplete or onError, and all signals to a subscriber are serialized. The JDK contains the same interfaces in java.util.concurrent.Flow since Java 9, and Reactor offers adapters between the two.
Open with
Reactive Streams is a small specification for asynchronous streams with backpressure, so that libraries like Reactor, RxJava and the reactive database drivers can work together. It has four interfaces.
Then, if they want more
Publisher has a single subscribe method. Subscriber has four callbacks: onSubscribe, onNext, onError and onComplete. Subscription is the link between one publisher and one subscriber, with request(n) to signal demand and cancel to stop. And Processor is both a Subscriber and a Publisher, a stage in the middle of a pipeline. The order of signals is strict.
Calling subscribe leads to onSubscribe with the subscription, before anything else. Nothing flows until the subscriber calls request with some n, and the publisher may then send at most n onNext signals in total, more as further demand arrives. Then optionally exactly one terminal signal, onComplete or onError, and nothing after it.
Signals to a subscriber must be serialized, never concurrent, so the subscriber can keep state without locks. Since Java 9 the same interfaces exist in java.util.concurrent.Flow, which the JDK's HTTP client uses, and Reactor has JdkFlowAdapter to convert between Flow and Flux. And if asked about request Long.MAX_VALUE: that means unbounded demand, which effectively switches off backpressure for that subscriber.
About this answer
- Last updated
- 12 November 2026
- Versions it names
- Java 9
- 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 "Describe the four interfaces of the Reactive Streams specification and the order of...": https://scrivio-interview-library.netlify.app/spring-boot/reactive-fundamentals/1cb50165fb/