Reactive and Functional Coding #
Reactive systems are measured in terms of resilience, responsiveness, elasticity, and message-driven as in the Reactive Manifesto. Many frameworks are available to help developers implement reactive systems; between all of these frameworks, we are interested in the technologies that enable the construction of reactive systems through Functional-Reactice-Programming (FRP) abstractions, particularly ReactiveX and Reactor.
The core of FRP is the Observable pattern described by the Object-Oriented paradigm (GoF Design Patterns). The observable abstraction allows a component to be notified when changes occur instead of pulling the system for changes.
An Observable system is lazy, event-oriented, and uses push/notifications to propagate state changes. In contrast, a traditional imperative system is eager and needs to pull the system state to detect changes continuously, consuming computer resources unnecessarily.
Both ReactiveX and Reactor share common operations described using marble diagrams. The idiom is based on functional programming: map, filter, flatMap, reduce with the addition of more sophisticated ones responsible for merging async operations.
Angular uses ReactiveX, consequently the Observable pattern, as the foundation for its event-oriented and reactive state management. Additionally, Java 9 introduced the Flow API, further strengthening the adoption of FRP by standardization of the observable pattern. A reactive multi-threaded java system implemented using FRP improves memory utilization dramatically by the non-blocking nature of code execution.
Engineers have many choices implementing non-blocking multi-threaded systems, usually in counter-intuitive and complex ways. An FRP multi-threaded implementation is an elegant alternative that is also compatible with the deterministic and idempotent nature of FP functional programming.
In other words, FRP is an essential tool to write modern reactive microservices in the cloud with excellent performance.