The Reactive Rollercoaster
Wyko Rijnsburger
1. What, Why?
2. Elements of a Reactive JVM App
3. Real World Example
4. Tips
"Programming paradigm concerned
with data stream and the propagation
to change"
https://en.wikipedia.org/wiki/Reactive_programming
Writing asynchronous, non-blocking
code using Reactive APIs
val product: Product = getProductSync()
val offer: Offer = getOfferSync()
return combine(product, offer)
Thread
getProductSync()getOfferSync()combine()
Thread Thread Thread
getProductSync() getProductSync() getProductSync()
val product: Future<Product> = getProductAsync()
val offer: Future<Offer> = getOfferAsync()
return combine(product, offer)
Thread
getProductAsync()getOfferAsync()combine()
getProductSync() getOfferSync() combine()
combine()
getProductAsync() getOfferAsync()
"Handle concurrency with a small
number of threads and scale with less
hardware resources"
https://docs.spring.io/spring/docs/current/spring-framework-reference/web-reactive.html
Reactive API
● Reactive Streams specification
● "Reactive Streams is an initiative to provide a standard for asynchronous
stream processing with non-blocking back pressure."
● JDK9: java.util.concurrent.Flow
Project Reactor
Observable<T>
Single<T>
Flux<T>
Mono<T>
RxJava
0..N
0..1
● .map()
● .flatMap()
● .zip()
Elements of a Reactive
JVM App
HTTP Client
Business logic
Controller/API
Product
ProcessedProduct
Backspin Driver/RestTemplate=
Spring MVC=
HTTP Client
Business logic
Controller/API
Mono<Product>
Mono<Processed
Product>
Non-blocking HTTP client
AsyncHttpClient/WebClient=
DeferredResult
Spring 5 -> Return Reactive Types=
HTTP Client
Business logic
Controller/API
Observable<Product>
Mono<Processed
Product>
Non-blocking HTTP client
AsyncHttpClient/WebClient=
Spring MVC + DeferredResult
WebFlux=
Mono<Product>
val p: Mono<Optional<Product>> = getProduct()
HTTP Client
Business logic
Controller/API
Observable<Product>
Mono<Optional<ProcessedProduct>
Non-blocking HTTP client
AsyncHttpClient/WebClient=
Spring MVC + DeferredResult
WebFlux=
Mono<Optional<Product>>
App API
val bundles = bundleService.getBundles(id, countryCode)
.onErrorReturn(emptyList())
val specifications = productService.getSpecifications(id)
.onErrorReturn(Optional.empty())
val offers = offerService.getOffers(id)
.onErrorReturn(Optional.empty())
Mono.zip(bundles, specifications, offers)
.map { doSomething() }
.flatMap()
"Ordering of the flattened values: this operator
does not necessarily preserve original ordering,
as inner elements are flattened as they arrive."
.flatMapSequential()
"Ordering of the flattened values: this operator
queues elements from late inners until all
elements from earlier inners have been emitted,
thus emitting inner sequences as a whole, in an
order that matches their source's order."
● Performance: to
● Readability:
● Debugging:
● Number of unexpected issues:
● Future readiness:
Tips
Start from the top
(HTTP clients/DB drivers)
Use Tomcat 8
Use Optional within
Reactive Types
Convert Reactive Types to
RxJava1 when using
Hystrix
Set Isolation Strategy to
Semaphore
Performance test
Thanks!

The Reactive Rollercoaster