Going Reactive With Spring Data

Why Reactive?

In a nutshell, reactive programming is about non-blocking, event-driven applications that scale with a small number of threads with back pressure as a key ingredient that aims to ensure producers to not overwhelm consumers.

— Rossen Stoyanchev

The main goal of Reactive Streams is to govern the exchange of stream data across an asynchronous boundary — think passing elements on to another thread or thread-pool — while ensuring that the receiving side is not forced to buffer arbitrary amounts of data.

— Reactive Streams

Relevant Projects

Reactive Streams

Common interfaces and a TCK.

Allows for interoperation of various implementations




Project Reactor

+ other more specialized

Flow API

Semantically equivalent to Reactive Streams.

Part of the JDK.

Rules of Reactive Streams apply.

Which to pick?

Ask the developer of RxJava.

Spring Framework 5.0

Reactive server side web framework based on Project Reactor.

Spring Data - Kay Release

Reactive Persistence API for

  • MongoDB

  • Cassandra

  • Redis

Uses Reactor by Default, but supports RxJava as well.

Threads in Servlet Apps

1 Thread per CPU Core

Overload → Network based Time Out

With I/O

1 T/Core + 1/Connection (???)

Works only with full/even load.

Assymetric Load → Wasted Resources

Overload → Network based Time Out

Reactive Streams

The Contract


Publisher may only send what requested.


Combines Subscriber and Publisher

Functional Processors

  • map: transform events

  • flatmap: many elements from one

  • filter

Controlling Processors

  • buffer n elements

  • stop after some time

  • work on a special Thread-Pool


Publisher → Mono, Flux

Processors → methods on Mono & Flux

reactive Spring Data

Lets play!

What about JDBC?

Nobody wants to push JPA through Reactive Streams

Spring Data JDBC

Oracle Works on Async SQL-API

Not Flow/Reactive Stream based

Spring will take a look

The idea of a reactive JDBC template

There are APIs

Run on Thread Pools

Jens Schauder

Dad, Board&Roleplaying Gamer, Runner, Freeletics Masochist


JUG Organizer

The Demo Repositories

From this talk

From the long version of this talk

Similar to the first but better documented

better for self study