Simple reactive microservices using rxJava Observables

Linas Naginionis
soundvibe
Published in
2 min readNov 24, 2015

Functional Reactive Programming is what interest me the most nowadays. RxJava is a great library which implements reactive extensions for the JVM. There are many reasons why functional reactive programming using RxJava is beneficial:

  • It fully embraces immutability. Instead of mutating state in place, you just pass it through the chain.
  • It encourages you to write pure functions
  • It’s very flexible
  • It’s highly composable
  • Easy to recover from possible errors
  • It uses push instead of pull
  • Same code can be sync or async
  • It’s easily testable
  • It supports backpressure
  • It’s polyglot library. Same concepts can be applied in different languages
  • It helps you to separate your business logic into commands and events.
  • It’s fun :)

As you probably now, akka is a framework which also can be used to write reactive applications. One of the akka selling points are actors and their ability to communicate with each other through the network. This makes akka very useful when writing microservices, especially when microservices now are on the rise.

I like the concept of RxJava more though because it provides you with more functional approach to build reactive applications. So recently I started thinking,- why can’t Observables be easily used in distributed environment?

And then I decided to write a library which would allow me to call commands (which are implemented using Observables) from different applications. This way you could easily decouple your services. They could work independently without even knowing about each other. You would compose them in your client applications. So the code now looks like this:

There are some more configuration needed to be done but I just wanted to show the main concept of the library.
All the commands will be wrapped into hystrix commands implementing circuit breaker pattern and allowing to have some fallback mechanisms. So if the main server is busy or not responding, fallback server will be used to execute the same command. Also hystrix monitoring dashboard can be used because all the metrics will be sent over the network:

Hystrix Dashboard

In summary, I wanted to create a thin library for building simple reactive microservices. I think the first results are very promising. What’s your opinion about this?

Update
You can find my library on the github already, it is called reacto.

--

--