mooc-notes

Notes from online courses

View on GitHub

Spring WebFlux: Getting Started - Pluralsight course by Esteban Herrera

Module 1 - Course Overview

Reactive web applications is the solution for growing number of internet users in this day and age

Topics covered

Module 2 - Introducing Spring WebFlux

Course Overview
What is Reactive Programming?

Usually means 2 things:

You can build a part of your application using reactive pogromming but that doesn’t make the system reactive. What makes a system reactive depends on the traits it follows as defined in the Reactive Manifesto.

Reactive programming

In imperative programming, the ability of a program to react to change in events is not implicit. It needs to be defined explicitly. For e.g., if var b depends on value of var a. If a changes, b doesn’t automatically change unless explicitly programmed.

One way to achieve this is via the Observer pattern - that is with a Producer and a Consumer. One drawback of the Observer pattern is that the Consumer doesn’t have the ability to tell the Producer to send events at a different rent if it is unable to keep up with the rate at which the producer is sending messages. This ability to be able to handle the rate of event production at a different rate or only at the rate at which the Consumer can handle is called backpressure.

Reactive programming model
Non-Blocking

Blocking is another work for synchronous. Web server has a thread pool. Each request is handled by a thread and the maximum number of requests that a server handle at the same time depends on the # of threads in the thread pool. If each thread uses a memory of 1MB, then the program needs 500MB to start. This is inefficient use of memory when there is a blocking call performed as part of a request because of the wait without performing any other task. Also an inefficient use of CPU cycles because server doesn’t perform anything else while waiting.

Evented web servers are more efficient because request coming in is split into multiple events. If there is a blocking operation is to be performed, they are taken care of by worker threads while the threads are freed up to handle additional requests. Once the worker thread completes, the event in the event loop queue is due to be processed.

Reactive Streams

An initiative to provide a standard for asynchronous stream processing with non-blocking back pressure. Have no relationship with Java Stream API.

Java Stream API vs Reactive Streams
Spring WebFlux

New Reactive Web Framework that comes with Spring Framework 5. It doesn’t replace Spring MVC. You can even use both at the same time.

Spring MVC vs Spring WebFlux

Spring MVC

Spring WebFlux

In most cases, it’s the Servlet API that forces to use the blocking model, not the server

Reactive all the way

TODO: insert image from Evernote Remember to use reactive extensions in all layers of the stack

Project Reactor is the default Reactive library to work with for Spring WebFlux.

Things to remember

Module 3 - Learning Reactive Programming with Reactor

Module Overview
Reactive Streams
Core Interfaces
Publisher
Project Reactor
Demo: include Reactor in a Maven project

skipped taking notes

Demo: Mono and Flux

skipped taking notes

Demo: Operators
Things to remember