Reactive Programming in Java.

reactive-programming

Introduction

Have you ever been in a situation where you invited 4 neighbors or so to the PPV game of the year and you casually mentioned it’s an open invitation and you can invite others thinking they won’t :-), and you end up with a lot more than expected, well, you have to “REACT” to that, right? Your neighborhood’s reputation as the host master is on the line here.  Not to worry though, you have planned that in advance, you have a large group of friends who can “Act” on your behalf, who are called “Actors”, they’re waiting for your asks or jobs and you can delegate tasks to those actors without worry, they know what to do and they can communicate using messaging, they won’t waste your time or your cycles asking silly questions, they’re resilient too, they can sustain failure and they know how to cooperate to recover, they’re independent individuals with no strings or threads attached. Putting the humor aside, this is a typical modern web application architecture common use case.

Modern’s day web applications are increasingly under pressure to provide a richer user experience, to have the ability to support hundreds of concurrent users with few thousands concurrent requests or calls a day at the startup-phase, however that could increase to millions if the venture proved to be successful and need to grow, and you need to react and adopt without fundamentally changing the architecture or the technology building blocks. The Modern web app will fail gracefully and recover seamlessly from unexpected failure without negatively impacting the user experience. Also, it’s required to provide a relatively fast response time, in milliseconds instead of seconds.

Reactive programming is not new, it was just forgotten for some time, recently, it resurfaced or resurrected due to the recent breakthrough in virtualization, containers, cloud computing and the internet and the advances made on the hardware side in terms of significantly reducing the cost of acquiring or leasing computing, storage and networking capabilities.

The Reactive paradigm is supporting the following computing qualities, I’m going to use the “Triple R” notation to make it easier to memorize, -you don’t need to search for that, I just came up with it :-)-

  • Reactive (scalable)

Has the ability to seamlessly handle an increasing or growing number of requests without negatively impacting the user experience, it’s even better if it supports on-demand computing by scaling up or down the consumption of resources based on the current system demand (Elasticity).

  • Responsive

The increasing concurrency and load will not negatively impact the response time.

  • Resilient

The ability to recover from unexpected failure without impacting the user experience or causing a complete system downtime or full system recovery, also being consistent without causing erroneous transactions.

The Reactive model is achieving the above by adopting the Observer and the Actors patterns, using Event Driven Architecture, Asynchronous Messaging and Stateless Computing as a foundation; the computing tasks will be independently distributed.

Functional Programming and the Reactive Paradigm

While Functional programming is sharing a lot with the Reactive paradigm, however, that doesn’t mean you can only do this in Scala or Haskell.

Reactive Programming and Java

Some firms have already developed the capabilities to build reactive systems in Java by providing the reactive foundation such as Lightbend (formally Typesafe); they created several capabilities in that space to support the Reactive paradigm, now we have Reactive MVC (Model View Controller) using the Play! Framework and reactive messaging platform known as Akka and a Microservices platform known as Lagom.

Reactive Programming in Java and faster time to market

By providing those out of the box Reactive capabilities, you already have the foundation defined and built for you; such as out of the box controllers’ and actors’ wiring and infrastructure.

Lightbend Activator allows hot deployment, you can fix your code and continue to run and test your application without redeployment. Nowadays, time-to-market is an equally important business and architecture requirement as any of the other essential non-functional requirements.

Reactive Open-Source based MVC stack

This is a sample open-source stack we are using to build enterprise applications and we have an extensive pleasant experience with it, you can also get an Enterprise support subscription for that if you’re going to run in the Enterprise. Give it a try if you wish, it’s a lot of fun to learn and use.

  • Play! Framework and Activator
  • Akka
  • Bootstrap 3.6 UI/UX + JQuery
  • PostgreSQL 9.5 DB
  • IntelliJ IDE as a development environment
  • Deploy on Heroku for online sharing and testing

You can download, watch the video tutorial and read more about Activator and Akka here.

 

Disclaimer

Those are my personal views and not representing the people I worked with, the companies I worked for, or my/our past and present customers in any shape or form. Any resemblance to real life use cases or situations is accidental and not intentional in any way, shape or form.

Hope this is helping some and again I understand other’s experience and views could be completely different than mine and I completely respect that.

References

https://www.lightbend.com/community/core-projects/play-framework

 

 

 

 

 

 

 


2 thoughts on “Reactive Programming in Java.

Comments are closed.