Skip to main content

Reactive Programming

Reactive programming focuses on non-blocking, asynchronous execution

The Reactive Manifesto

Responsive

  • The System responds in a timely manner
  • Responsiveness is the cornerstone of usability and utility
  • Reponsiveness also means problems may be detected quickly
  • Responsive systems provide rapid and consistent response times
  • Consistent behavior simplifies error handling, builds end user confidence, and encourages further interaction

Resilient

  • System stays responsive in the face of failure
  • Resilience is achieved by replication, containment, isolation, and delegation
  • Failures are contianed within each component
  • Parts of the system can fail, without compromising the system as a whole
  • Recovery of each component is delegated to another
  • High-availability is ensured by replication where necessary

Elastic

  • The System stays responsive under varying workload
  • Reactive Systems can react to changes in the input rate by changing the amount of resources allocated to service inputs
  • Reactive Systems achieve elaticity in a cost effective way on commodity hardware and software platforms

Message Driven

  • Reactive Systems rely on asynchronous message passing to establish a boundary between components
    • This ensures loose coupling, isolation, and location transparency
  • Message passing enables load management, elasticity and flow control
  • Location transparent messaging makes management of failures possible
  • Non-blocking communication allows recipients to only consume resources while active leading to less system overhead

Features of Reactive Programming

  • Data Streams
  • Asyncronous
  • Non-blocking - Process what is availble and ask for a notificaiton when more is available
  • Backpressure - The ability of the client to throttle data
  • Failures as Messages - Exceptions are processed by a handler function

Reactive Streams

  • Reactive Streams API was started in 2013 by engineers from Netflix and other companies. It was officially released 2015 and is now part of Java 9 JDK 92834787bd1f2632805a67e158738e69.png
  • spring-webflux is a whole new non-blocking API for Spring 4702ef7341bfe8112eff9b0c8e55221e.png

Spring Reactive Types

  • Mono - A publisher with 0 or 1 elements in datastream
  • Flux - A publisher with 0+ elements in datastream