This repository contains a collection of examples/patterns that can be adopted to make a java based micorservice reactive
.
GOV.UK Pay, a payment platform for the government consists of many microservices. Our backend is RESTFUL
by default, and we use Dropwizard
for most of java based microservices.
Dropwizard is based on Jetty, a lightweight java http/servlet container.
Architecturally, jetty is a thread based synchronous (blocking) request processing container, similar to many other traditional java servlet containers.
Over the last decade or so, asynchronous/non-blocking request processing architectures are gaining huge traction across the industry, primarily due to the capabilities of optimum usage of available resources (H/W, S/W) allowing significantly higher throughput. Although this model already been widely used in other (non-java) tech stacks (e.g. NodeJs, Scala/Akka), it has been a slow progress in Java community due to its lack of language features (functional) and lack of libraries / frameworks. However, with the introduction of Java 8 features and the appearance of several reliable libraries/frameworks (e.g. guava listenable futures, Rx Java, Akka) Java landscape is slowly shifting towards asynchronous non-blocking programming models.
The biggest challenge yet is the change of mentality among the developer community from a more traditional synchronous programming models to more functional / reactive programming models in order to gain the advantages these recent developments.
This repository presents few alternative non-blocking programming models / patterns and technologies for Java. We expect to adopt these (and possibly more) as we extend GOV.UK Pay in future.
- Here is a good reference to read more about
reactive programming
principles and examples. - Here's a comparison of Dropwizard vs Ratpack. http://phillbarber.blogspot.co.uk/2016/01/choosing-between-ratpack-and-dropwizard.html
####1. Handling inbound requests
This is about how to handle HTTP/REST requests in a non-blocking way.
- See dropwizard example
- See ratpack example
####2. Handling outbound requests
This is about how to handle outbound HTTP/REST requests in a non-blocking way.
- See dropwizard example
- See ratpack example
- See hystrix based example
####3. Handling internal workflows
This is about how we can compose a internal workflow of bunch of functions together in a reactive way.
- See dropwizard example
- See ratpack example
####4. Decoupling of microservices using an event source
This is about how we can compose a internal workflow of bunch of functions together in a reactive way.
- See publisher
- And subscriber
###References
- Ratpack Ratpack
- Java8 CompletableFuture
Other options (not explored)