www.apress.com

3/6/17

Microservices or Micro-Applications?

By Josh Juneau

No matter which direction you turn nowadays, microservices is the buzzword that is most often heard. Everyone is starting to use microservices, and traditional Java EE applications seem that they are becoming a thing of the past.  

Whenever I hear someone say that traditional applications are “monolithic” and “no longer a valid path for development”, or even “obsolete”, it makes me question whether those claiming that microservices solve all of today’s problems have actually developed applications for the real world.  Sure, microservices can be a very effective way to implement an application, but they may also not be the correct fit in all cases.  We have many tools in the shed…especially as Java application developers, and that is what makes the JVM such a rich platform for development.  We have lots of options…and microservices are just one approach.

I believe that traditional Java EE applications will continue to be an effective and worthwhile solution for the long term.  There are thousands of Java EE applications in use today, and they are not all migrating to microservices overnight.  

On the other hand, you can sometimes blend aspects from microservices into monolithic applications. Think about this…how many pieces of your traditional application do you copy and paste into other applications in order to achieve the same functionality in both?  In such cases, it may make sense to abstract that functionality out of the application and create a mini application or a microservice that produces that same functionality and exposes it via JAX-RS.  That way, each of the applications that require that functionality can simply make a web service call, and if a change needs to be made to the underlying logic then it can be done in one place rather than in each of the applications.

What I’ve just described can be a good tack for taking small steps toward smarter development – not necessarily jumping into developing microservice applications for everything, but simply breaking down our applications bit-by-bit into smaller services. These services do not even have to be “true” microservices.  In fact, a true microservice architecture may be too big of a headache to take on in some situations.  

A true microservice runs on its own, decoupled from any databases or systems.  This requires a change in development practices and manpower to manage the health of different services, etc.  Although there are some great solutions in place for microservices such as Payara micro, it may make sense to deploy micro-applications into a single container, following the traditional Java EE application architecture.  

For instance, an application may be comprised of several micro-applications, each of them deployed to the same application server instance.  While this does not provide as many scalability options and safeguards as a true microservice architecture, it can certainly be easier to manage and a great model for making use of common code source across a number of applications.

Here’s a diagram showing micro-applications in a single container:

Juneau Fig1

Of course, this architecture has its downfalls.  For instance, the obvious issue arises when too many applications are deployed to a single container.  Memory could be at a shortage, or processing from one of the applications may take a toll upon each of the other deployments within the container.  To be frank, this architecture is likely best for a small to medium sized user base.  Applications with high amounts of traffic may require a load balancer with multiple servers.

About the Author

Josh Juneau is a professional application developer who enjoys working with database technology and learning new languages to develop sophisticated solutions. Josh has been an Oracle database administrator and PL/SQL developer for many years. He became interested in Java for developing web-based solutions, which led to a passion of Java technology as a whole, including other languages on the JVM. He's active with the alternative language Jython and also other languages that run on the JVM. Josh is also active in the Java EE (Enterprise Edition) community, contributing to expert groups for JSR 372 and JSR 378 to help advance the technology.  Josh is the author of the forthcoming Java 9 Recipes as well as several other Apress titles.