I been searching on the web but im a little confused on what exactly is a java microservice. I mean i know what a web service is, and im told that a microservice is the following per wiki:
In computing, microservices is a software architecture style in which complex applications are composed of small, independent processes communicating with each other using language-agnostic APIs.
and the properties of a microservice are:
Properties of microservices architecture:
It's a kind of architecture The services are easy to replace Services are organized around capabilities, e.g. user interface front-end, recommendation, logistics, billing, etc Services can be implemented using different programming languages, databases, hardware and software environment, depending on what fits best Architectures are symmetrical rather than hierarchical (producer - consumer)
but i need a concrete java example to understand how i can make a microservice. Does anyone have a example you could provide ?
A microservice is exactly like its name suggests. It's a tiny service that performs a very simple function.
So yes, in terms of code, you're probably looking at a REST service. Note that any other API style would work. It doesn't have to be REST, however it must be language agnostic for you to draw all the benefits.
But the idea is bigger than that. The idea behind it is that they are very specialized and there's no big business workflow attached to they. For example, if you have a service that processes payments, then writes an audit log, then notifies the customer. I wouldn't count that as a microservice. Writing an audit log, that'd probably be a microservice, notifying the customer too, processing the credit card as well. Your system would coordinate that business workflow (the 3 steps mentioned above) by calling the 3 necessary microservices. So your system is a coordinator and you don't worry about implementing the business functions.
Microservices don't try to think too much, they just do as they're told, but they do it quickly.
So in short. Take a very simple business function, put a REST API in front of it. And you have a microservice.
There are several interesting properties with microservices:
But you should also consider some drawbacks
It's a lot harder to maintain a consistent transaction across all these calls. If you need to roll back, you'll need JTA to rollback all the REST calls. That can be a pain and doesn't perform very well in my experience.
Tracking a transaction through the system in order to troubleshoot can be pretty rough if you don't have consistent logging and a consistent transaction id
It might get tricky to find where a defect was introduced if the ground is constantly shifting due to deployments that may have side effects.
Obviously all these REST calls can stack up to be pretty expensive. I'm not necessarily talking about the transport since it's likely all your microservices would live in the same data center. But every time you make a call over the network, you have to marshal/unmarshal your data and that could quickly get expensive CPU-wise.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With