Is Non-Blocking the Same as Reactive?

Learn about the similarities and differences between non-blocking approaches and reactive approaches.

It depends on whom you ask that question. “Reactive” is a generic concept describing something as being triggered by a previous action.

You could argue that programming techniques that follow a non-blocking approach are reactive programming styles because you normally use a callback function that reacts to the result. In that broad scope of the ‘reactive’ word, using a CompletableFuture, or any other tool based on promises, with callbacks would be considered reactive programming. However, people normally refer to these libraries and APIs as asynchronous programming.

It’s more common to talk about reactive programming when our code uses one of the existing frameworks that follow the Reactive Streams spec. Some popular reactive frameworks are ReactiveX (RxJS, RxJava, etc.), Akka, and Project Reactor (the one used by WebFlux). Java 9 also introduced the Reactive Streams specification with the Flow API so the implementers can choose the Java API standards for their libraries. However, that hasn’t worked so far, and most of the reactive libraries still use their custom classes. In any case, all these frameworks implement (with some slight differences in naming) patterns like ObservablesPublishers, and Subscribers.

Additionally, these reactive frameworks adopt the backpressure concept. The main idea of backpressure is that the subscriber has control of the stream, so the consumer can signal the publisher to stop producing data instead of having to accumulate it in buffers.

Project Reactor implements backpressure, as we’ll see and demonstrate later in this course.

Get hands-on with 1000+ tech skills courses.