0:0037:17

First steps with reactive programming in Java

Kamila Oliveira 37:17 2021

Reactive Java runs on fewer threads, but you must relearn how to debug

A Spring MVC service under heavy request volume can slow down and even hit an out-of-memory error, while a non-blocking reactive stack is built to run on fewer threads. Backend developer and Microsoft MVP Kamila Oliveira, who uses Project Reactor in all her work, traces the path from the Reactive Manifesto to a live Spring WebFlux API. What changes in code, and what does the switch cost?

Learn when to return Flux or Mono and see a reactive MongoDB CRUD API built with Spring WebFlux

Watch on YouTube

In short

Kamila Oliveira introduces reactive programming in Java, from the Reactive Manifesto and the Reactive Streams interfaces to RxJava operators, backpressure, Flux and Mono. She explains why Spring WebFlux was built as a non-blocking alternative to Spring MVC and demonstrates a reactive CRUD API backed by MongoDB, closing with the benefits and costs of the paradigm.

“It is a feedback from the receiver to the producer or from the subscriber to the publisher that he is not supporting the load.”
“Spring Web Flux was developed because we need the non-blocking application.”

What you will learn

  • Explain the four Reactive Manifesto principles: responsive, resilient, elastic and message driven.
  • Distinguish the Publisher, Subscriber, Subscription and Processor interfaces defined by Reactive Streams.
  • Choose Flux for endpoints that return zero to many items and Mono for zero or one item.
  • Identify the dependencies and repository changes needed to move from Spring MVC to Spring WebFlux.
  • Anticipate the learning curve and different stack-trace debugging that reactive code brings.

Key takeaways from the speaker

  • java
  • backend
  • reactive programming

Details

Level
Beginner
Format
Tech talk
Technical depth
Practitioner
For
Early career, Mid-career
Length
37:17
Published
June 2021

Questions this talk answers

What are the principles of the Reactive Manifesto?

A reactive system is responsive, resilient, elastic and message driven, staying responsive under failures and whether it receives one request or ten million.

What is backpressure?

Backpressure is feedback from the subscriber to the publisher that it cannot support the load, so the flow of data can be adjusted.

What is the difference between Flux and Mono?

A Flux can emit zero to n events, while a Mono emits zero or one event; both pass through onNext, onError and onComplete.

Why was Spring WebFlux created alongside Spring MVC?

The servlet API is blocking by definition, and the NIO API added in Servlet 3.1 did not match the rest of it, so a non-blocking stack running on few threads was needed.

What changes when building an API with Spring WebFlux instead of Spring MVC?

You use the WebFlux starter, a reactive database driver and repository such as ReactiveMongoRepository, the WebFlux variant of springdoc, and endpoints that return Flux or Mono.

About this talk

Let's talk about the principles of reactive programming and how Java has evolved since object orientation, the concepts of reactive programming that started to come with Java 8 and how this led to the emergence of Webflux. And we will see an example of an API with Spring Webflux using the Reactor library and the asynchronous server Netty.

Topics

Software engineering and cloudSoftware developmentSoftware architectureBack-end and API developmentSystem designProgramming fundamentalsBuild technical depth

Related talks

Browse the library

Why Jetpack Compose?

Miriana Itani Android Team Lead

A Compose counter that never counts, and what it teaches about state

Intermediate Software engineering and cloud 2022