liveBook · Manning

Reactive programming

As explained in Spring Start Here, Second Edition

A reactive approach structures asynchronous operations around nonblocking results and declared dependencies.

Reactive programming organizes asynchronous work as tasks with declared dependencies. Instead of keeping a thread waiting during I/O, the application can let available threads execute other tasks. section 11.4

The practical distinction is how an application handles a flow of work:

  • In a nonreactive flow, one thread performs the tasks in sequence and waits when a task blocks on I/O. section 11.4
  • In a reactive flow, tasks declare dependencies; available threads can work on independent tasks instead of staying idle. section 11.4
  • Choose WebClient for a reactive app; for a nonreactive app, use RestClient or OpenFeign instead. section 11.6

A banking debt calculation

To calculate a customer's total debt, an application may call several services, including services for external and internal credit. In a sequential flow, waiting for those calls can block the thread. A reactive design represents work as dependent tasks so other available threads can make progress. section 11.4

Calling a payment endpoint

A Spring proxy can use WebClient to POST a payment and return a Mono<Payment>. The returned task participates in a dependency chain; WebFlux subscribes to the task returned by the controller, and WebClient subscribes to the task that supplies the request body. section 11.4

Figure 11.8 An analogy of the way a reactive app works. A thread doesn’t take a request’s tasks in order and wait when it’s blocked. Instead, all tasks from all requests are on a backlog. Any available thread can work on tasks from any request. This way, independent tasks can be solved in parallel, and the threads don’t stay idle.

Visualizes the task backlog: available threads can take work from different requests rather than wait on blocked operations. section 11.4

How Spring Start Here, Second Edition covers it

How deep it goes
Explains task dependencies, thread use, and subscription flow, while recommending deeper study before implementation.
Examples
Uses a banking debt calculation and a WebClient payment request to illustrate blocking and reactive task execution.
What it assumes
Assumes familiarity with application basics and recommends deeper study before implementing reactive applications.
What you can do after
Evaluate whether WebClient suits a reactive app or RestClient and OpenFeign suit a nonreactive app.
How it connects
Connects reactive programming to WebClient, Spring WebFlux, REST clients, and asynchronous tasks.

Also explained in

Compare how 8 books explain reactive programming →

Related concepts

This explainer was generated by Manning's knowledge graph from the text of Spring Start Here, Second Edition. The section links point to the parts of the book it draws on.