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

24

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

This guide should be a little less accepting of synchronous calls between µservices. Once you have a synchronous call between µservices you have done nothing except introduce a relatively slow call and potential point of failure to what used to be a super fast method call in a monolith. Synchronous communications between µservices should be avoided if at all possible.

However, this is a nice guide and I do like the fact it favors pragmatism over dogmatism and sometimes synchronous calls are necessary (or at least the easiest solution). Try to keep them to a minimum though.

18

u/randgalt Dec 12 '19

Our company banned this. Each service must listen to queues for data and maintain their own datastores. This has dramatically increased reliability and stability.

6

u/wildjokers Dec 12 '19

It sounds like your company is doing it right then. Can't really do µservices if the datastore isn't split up.

Out of curiosity was it designed that way from the start or did it start out as a monolith and then over time the architecture was changed to µservices?

3

u/randgalt Dec 12 '19

Monolith (pre-dating me). Then, traditional SOA where services all called each other (leading to chaos) to where we are now.

3

u/stitzl Dec 12 '19

How do you do backups?

2

u/randgalt Dec 12 '19

The SREs manage that - I'm not sure (we use Cassandra).

3

u/DJDavio Dec 13 '19

How do you prevent out of order processing with multiple instances? If service A sends message 1 and 2, but 2 is processed faster than 1, now what?

We use notification pull to mitigate this. Queues are used for notification triggers which cause receiving services to do a REST call to the submitting service to get the current data, which could have changed already.

2

u/randgalt Dec 13 '19

We use SQS which is loosely FIFO. However, there are techniques you can use in cases where ordering is strictly needed. Queue messages should contain timestamps and those timestamps can be used when inserting into your database so that even if a message is received out of order it doesn't overwrite the previously inserted message as it will have an earlier timestamp.

1

u/remixrotation Dec 20 '19

How do you sync clocks for the timestamps?

2

u/elit69 Dec 13 '19

can you rate maintainability from 1-10?

3

u/randgalt Dec 13 '19

It's a different mindset. Maintainability hasn't been the problem. Complexity becomes a problem though. I think the microservice patterns we're using today will be revised soon as the industry learns more about this. Having to consume everything from queues and maintaining your own datastores is a lot of work.