r/java • • Dec 12 '19

Java Microservices: A Practical Guide

https://www.marcobehler.com/guides/java-microservices-a-practical-guide
237 Upvotes

35 comments sorted by

View all comments

2

u/agentoutlier Dec 12 '19 edited Dec 12 '19

With proper project setup you can have a monolithic single executable running multiple microservices (EDIT I don't mean real microservices I mean architectural like microservices... I mean seriously people two wars deployed in the same java app server does not make it not a microservice just because they are on the same JVM). We do this with multiple (hundreds) of rabbitmq consumers.

We do this because lets face it booting up 10 microservices to run an application for demo or smoke testing is pretty tedious (and actually slow) even when using docker/kubernetes.

The trickiest part of microservices is JOINing data and dealing with (eventual) consistency. Because you are working across datasources you do not get the nice advantage of using JOINs or true database transactions. Speaking from experience it is very hard to port this kind of logic to microservices (assuming multiple datasources).

On the other hand Pub/Sub or Event pattern as those are very easy to microservices out. Thus if you see a workflow like that (e.g. batch processing) it should absolutely be microserviced out.

3

u/wildjokers Dec 12 '19

With proper project setup you can have a monolithic executable running multiple microservices.

Please explain. A single executable that contains "multiple microservices" seems to be a contradiction.

0

u/agentoutlier Dec 12 '19

You still make network calls (rabbit, http, kafka) etc but the same image/executable etc deals with it. That is the client and the server are running in the same JVM.

Microservices essentially provide high barriers (ignoring scaling for a second). The code is not shared. You can do the same with share nothing code base and have it all run in one app.

Regardless to the articles point monolithic applications should be designed like the above (whether or not they make network calls) otherwise you have a big ass snowball.

3

u/wildjokers Dec 12 '19

You're...describing a monolith. You can't have a "monolithic executable running multiple microservices", that is a non-sensical statement.

6

u/agentoutlier Dec 12 '19 edited Dec 12 '19

You are being pedantic. If you run all your services on one physical computer are they not microservices then? Or better yet if you run all of them on one VM instance are they not microservices then?

Microservices are a software development technique —a variant of the service-oriented architecture (SOA) structural style— that arranges an application as a collection of loosely coupled services.[1] In a microservices architecture, services are fine-grained and the protocols are lightweight.

The services in our Java APP are like plugins. They share no code and communicate through an external bus (rabbitmq). These mini apps can be shutdown and started up.

They can and indeed are deployed as separate entities in production.

Really what makes microservices microservices is talking through a protocol instead of directly through memory (and not sharing datasources but that can be argued).

I'm talking about the architectural style. You can have microservice architecture in a monolithic application unless you disagree? (personally I think you are just being contentions for the sake of it).

The traditional monolothic architecture is to have layers and to rely on all that stuff in the memory. The protocol is direct.

Its like all the downvoters got caught up on my first statement when I said running microservices in a monolithic app. .... I really deplore reddit right now...

1

u/wildjokers Dec 12 '19 edited Dec 12 '19

If you run all your services on one physical computer are they not microservices then? Or better yet if you run all of them on one VM instance are they not microservices then?

Yes, that is µservices because they are individually deployable. But that isn't what you said you were doing at first.

You can have microservice architecture in a monolithic application unless you disagree?

I strongly disagree. If you have separate wars/jars you can deploy individually you don't have a monolith. You seem to be doing yourself a disservice by calling your application a monolith. It doesn't sound like a monolith to me.

1

u/agentoutlier Dec 12 '19

Please explain. A single executable that contains "multiple microservices" seems to be a contradiction.

and now you say

I strongly disagree. If you have separate wars/jars you can deploy individually you don't have a monolith. You seem to be doing yourself a disservice by calling your application a monolith. It doesn't sound like a monolith to me.

I said single executable and meant it instead of monolithic.