Tag Archives: microservices

Thoughts on microservices. Part 3: Throwawayware.

Картинки по запросу throw away this

Microservices.. yes, nowadays they are everywhere! In my previous post I’ve shared my thoughts that sometimes just a monolith can do the required task without being cut into microservices. But it is wonderful if microservices are the most suitable solution! This is definitely lovely!

First, we’ve got a lot of benefit it provides to us, second, we’ve got a great technology support to implement them – there are a lot of frameworks and platforms helping us develop some really good microservices.

The most of the conference talks I have recently seen are basically “Hello world” talks. The main message is “Hey, look how easy it is to create a microservice!”, “Just few annotations, and you are up and running!”. How great this is!

But when it comes to real life, most usually between start of the project till the first really useful microservice there is at least one sprint. More often three sprints. You’ll say – “That is ok! We are serious people doing serious enterprise!”. I still ask myself – “What can be so huge in one microservice, that it may require several weeks to be created?”. “Why then this service is called MICRO?”

I’m not sure if there is an official definition of a microservice, but a well-established idea is that it is a piece of software which is designed to perform only one single function, but in the best possible way. It should communicate with the rest of the world with the most lightweight protocol possible, like REST. So, if we have a login functionality, a microservice should be able to login a user in the most fast, easy, reliable, secure way. Only login and nothing else. For logout there should be another service. The size and complexity of such a service are not in scope of micro, they can be of any scale. Technically, there should be only one function exposed, but what happens under the curtains are just implementation detalils.

This is why, the most of such services become really complicated, often even overengineered. From my experience, at the end of the day, each microservice in enterprise webapps becomes a usual three-tier application. It has its “UI” simplified to REST endpoints, it has its business layer with several services interfaces and their implementations, an infrastructure layer to talk to DB and other services. The interlayer communication is done via value objects. As a result, a usual call of a function of this microservice ends up with several data coping from one value object to another (in one of such microservices I’ve seen up to 14 of such hops). Why would you do this? The typical answer is if some part of the service changes, we will change only this part of it. Fair enough. If in return I ask, how many times in your life have you ever changed one of the tiers without affecting the others? Тhe answer is usually – never.

Once again, nothing wrong here. The complexity of the implementation of a microservice is orthogonal to the interface it provides.

Another question: how many times have you ever received a fully functional “freezed” interface definition? The spec that never changes? A guaranteed never to change document? In my case – never!

The changes are coming constant or even increasing speed. Even in terms of one API version. You may say: You are doing it wrong! You should plan more carefully, you should rethink your spec versioning policy etc. And you will be completely wright!

But.. there is something called real life! There are business needs that require quick reaction, quick change, quick time to market!

Looks like this constant change is just inevitable. For my 13 years in software development there were practically no projects that had really smooth stable development. A least every sprint there were some “tiny” spec changes, causing all codebase to suddenly go red. I’m sure I’m not the only “lucky” having this.

How should we solve this kind of problems in the microservices world? Its quite time consuming to create beautiful, complex, nicely architectured, (at least) three-tier microservices without frozen spec. As I already said, those spec changes usually require changes in all of the layers. This is hard! Most of us thought that’s just the way it is. Software development is hard.

But this situation kept me bothering. May be there is a way to expedite this change reaction? May be a microservice should be micro in all aspects? I mean really tiny? With as less internal abstractions as possible? Really tight coupled inside? When I’m writing this, I have a feeling I’m breaking the law. It is like I’m cancelling everything I’ve learned from the CS courses in the university. Why don’t we throw away all of the … tiers? Make it a really tiny one-tied micro monolith? A microlith? So that the object or even a direct line with data we receive from the infrastructure we transform to JSON object in one single class? With all the business logic also included in this one and the same class? You are absolutely eligible to say – “are you nuts?” What if the infrastructure changes? What if the Rest API changes? What if the business logic changes? You have to rewrite everything!

And then I suddenly say – “Yes! We will rewrite this service from scratch!”. Luckily, a lot of code in the service can be just generated. So, yes. We will rewrite it from scratch! We copy/paste. We do all the possible anti patterns. Only to make it work according to the spec and pass the tests! “But isn’t it a lot of effort?”. My answer is – “Pretty much the same as changing all of the classes in all of the three (or more) tiers!”. And people usually say – “Hmm…”.

This may sound really strange, but through several last projects, writing some really ugly small one tier microservices with really almost no architecture and no refactoring, then rewriting this from scratch saved me a lot of efforts. I have even created a name for this piece of software – “Throwawayware!”. Try to say it quick!

The next question that usually comes is – “Do you put this ugly thing in production??”.

My answer is: – “Ok, you got me! No, this does not go to production! May be sometimes..”. What actually goes there?

Putting this ugly little thing in production will be just catastrophic. That’s why I’ve tried some mixed approach.

First of all, we usually develop the tests to follow the contract. Yep, although I’m not a big fan of TDD, I think this is a good place to use it. Adjusting the tests to follow the spec and the contract is always the first priority to us!

Then we usually have 4 to 10 iterations on each microservice in this ridiculous “throw away” way. Funny thing is that up to 50% of the services do not even survive through those iterations! At some point the service may come obsolete even before production. This means that we usually save a lot of efforts for not creating something complex for something that will never be used (“Bingo!”).

Then when the service gets through those several iterations, we consider this service as “survivor”. At this time usually, the spec stabiles as well. And we do the same for each API version.

Just like the Garbage collector in JVM.. Haha! Yep, like the GC! Lovely!

For the survivors we usually make some really complex refactoring, or rewriting it completely new. We try to make their code really readable, expandable and maintainable. Quite often from the usage of those “throw away” implementations we can see some before unpredicted usage cases, like for example the pressure it should hold, or security, or fault times etc. This may end in three-tier architecture, but with really nicely designed layers.

Looks like this “two stages approach” works really well! Funny thing is that it fits perfectly in our SCRUM cycle. May be, I’m wrong, but this approach saved us a lot of effots and helped us establish good quality implementations in shorter time. In three projects so far.. We’ll see how it goes!

Any critic is welcome though…

Thoughts on microservices. Part 2. Evolution of Microprofile.io

Looks like public transport is a good place to blog. For several hours I just have a time on my own. I may stay focused on the topic.

So, I’m now on my flight from Novosibirsk to Moscow after wonderful CodeFest conference! I’ve got four free hours, an A/C plug and no free internet (yes, there is payed one). Only the views of immense Siberia from my window .. and the beauty of Aeroflot stewardesses disturb me a little bit when passing by…

I had an amazing time in Siberia! I had a lot of really exciting moments there! I met a lot of truly interesting people and had the pleasure to talk to them! Trip report to CodeFest will be published soon!

But this time on the plane I have I want to dedicate to some other thoughts I recently had in my mind, and they are about the evolution of MicroProfile.io.

I had the privilege to be invited to CodeFest to give my talk right about MicroProfile.io in Russian. I was very happy that the audience was so excited about this project. I had a lot of questions that kept me in the discussion zone for more than one hour after my talk. The interest was great!

The MicroProfile.io project is an amazing example of a community work! It is very young, but it evolves extremely fast! I was the eyewitness of the birth of the project, when it has started with just three specs inside CDI, JSON-P, JAX-RS. It was kind of brave move to start with just these specs, but the same time it was very wise IMHO. This ignited a lot discussion and community work. Shortly after that a brand-new Config spec was created, allowing us the creation of not only portable code, but portable configuration as well.

Community worked hard to establish what is really useful in the microservices world and created Fault tolerance, Health checks, Metrics and JWT propagation. The specs like OpenAPI, RestClient and OpenTracing made the picture complete. JSON-B came as a cherry on the top. Every new version of the MicroProfile.io came with some new specs and evolutions of the already available ones, definitely great! Let us not forget that all this happened only in about two years period.

Every time together with Ivan Ivanov we gave our workshop on MicroProfile, or we gave our talks about it we saw some really huge enthusiasm in the eyes of our attendees. Finally, there is a lightweight absolutely standardized and portable way to write microservices in Java world.

The platform vendors from their side made some really tremendous efforts to implement all of those specs. Some of the servers were rewritten like from scratch. Completely new projects like Helidon and Quarkus emerged.

Starting from MicroProfile version 1.2 (which I believe is mature enough) I’ve started using it in my projects. Although it is a bit hard with the testing, I’m quite happy about it. I just love standard code, I like the portability. I even have used it twice, when we had to switch servers from different vendors. It really went seamlessly. In one of my previous post I’ve described how easy it was for us to migrate to Quarkus one of our services. Almost copy/paste! The power of standards!

There are some things that nevertheless bother me. I’m reading carefully the discussion in the MicroProfile.io mailing list and I’m not sure if, for example, adding a persistence spec to the project will be a good idea. I know, a lot of services are stateful and persist a lot… but is it really relevant to microservices? Everything can persist and this is not something specific to microservices. Why then should we put it to the MicroProfile.io project? There are a lot of stateless services. They don’t need any persistence.

I had the pleasure to share these my thoughts with Emily Jiang at Voxxed Bucharest. I have proposed to start thinking a little bit differently – why won’t we make separate profiles relevant only specific problem we are solving? Should we have a special “Persistence profile”? Or if we want to make thing reactively we should establish a “Reactive profile”? And if we need more than one profile, we just combine them.

This may sound even absurd, but I believe, that current set of specs is just enough for MicroProfile.io. There are already 12 of them. Most of them are really microservices specific like Fault tolerance etc., other like CDI are the foundation. Should JPA spec one of the foundation specs? I really don’t think so. If CDI is really a glue to put it all together, JPA can be sometimes totally ignored, if the service is stateless.

I’m still not sure if I’m right in my thoughts. I sincerely wait for critics. But I believe that staying focused on microservice relevant specs is a better evolution path. There are more microservice specific thing to be discussed, like better servicemesh integration. Or a common set of server flags?

Currently these 12 specs in MicroProfile 2.2 solve all of my microservice specific tasks. It’s only the JSON-P spec that I’m not using it anymore, I do it all through JSON-B 🙂

Ok, our plane is approaching Moscow, I already see the Ostankino tower and the Moscow-city skyscrapers. Time to switch off the laptop..

Thoughts on microservices. Part 1. Does my app deserve to be microservice–based?

Ok, its ten minutes past 6.00 p.m. I’m on my way from Plovdiv to Sofia just right after the wonderful #jProfessional Plovdiv 2019. Although there are only 130 km between two cities, an express train makes them them for two hours and a half through beautiful Balkan mountaines. Just enough time to summarize some thoughts on microservices I recently had. I still wonder aren’t this thoughts too stupid, but they still bother me.

Just to mention, that this #jProfessionals Plovdiv was EPIC! It totally worth a separate post.


Картинки по запросу microservices everywhere

Everybody writes microservices, no matter the reason, for good or for bad. Most of the talks on conferences are about microservices. Every new project is expected to be with microservices architecture. If there is no buzzword “Microservices” nobody from customers would ever listen to you. Some of the juniors I have on my teams say – “Of course microservices! Is there another way? Monoliths? Ah, they are bad! Why? It’s obvious!”

So, technically, I see everybody trying to make their software with this architecture. Or they say the do microservices, although the most projects I’ve seen usually consist of 2–3 fat services. Those projects look like a monolith artificially chunked into pieces that talk REST to each other. People try to decouple this chunked elements as much as they can, but most of the time it’s really obvious that these parts are still logically very coupled and cant live without each other.

I quite often have the following conversation when I consult some project:

– “Ok, you’ve got 40 request per day. The interface is for internal use. You’ve got a team of four developers. Why are you doing six microservices, you’re routing requests with Istio, you’ve got an angular UI”

– “Pretty cool, ah?”

– “How do you spread responsibility in the team, each of you develop his own service?”

– “No, everybody is responsible for all of the code.”

– “What will happen if one of the services will fail?”

– “We throw exception and render code 500.”

– “How do you deploy it?”

– “We’ve got one ubuntu VM on AWS right now. There is docker installed there.”

– “You will run all of the services there?”

– “Yes, and the database.”

– “Will you ever scale?”

– “No.. may be up to 50 requests.”

– “What about security?”

– “Oh.. It will run in secure environment!”

– “What do you mean by secure secure environment?”

– “It will run in intranet.”

– “Ok, now a general question: what is the problem you are trying to solve with microservices?”

– “What do you mean?”

– “Why would you split the app in 6 independent apps?”

– “They are logically split. What’s wrong?”

– “Ok, 50 request per day, it can’t work if one or more services stop… Isn’t a JSF/Vaadin small app just enough for this?”

– “Man! You are such a retrograde!”

I start thinking to myself, well, may be I’m getting old. I believe many C developers think the same about us Java developers – “Look how much overhead they make!!!”.

But still I wonder, is it really worth making everything as microservices? Will this automatically guard you from all of the architecture problems? Or would it create new problems you didn’t have before?

This architecture IMHO should not be considered as absolutely universal. Quite often this causes additional unnecessary overhead. The same time most of the developers I use to know sincerely believe that this is the only way of doing things. They don’t even consider other approaches.

I believe, that we as developers/architects should first ask ourselves – “What are the problems are we going to solve when applying microservices architecture? Do I really need it?”.

Before starting a new project, I personally do a list of answers on a single question: “Why this app should not be a monolith?”. If I find myself at least three technical answers different from “This is modern!”, “Everybody does this!”, “We can do it with one team!”, I start considering microservices as a potential architecture for the requested app.

And every time I start a new project I remember myself the dialog above. Does my app deserve to be microservice–based?

This doesn’t mean, microservices are bad and monolith is good. This means, we as professionals should make the right choice for the right case. It is very hard to give recipes, but it is always a good idea just to think before applying a certain architecture!

By the way, there are two great talks by Daniel Bryant “Seven deadly sins of microservices” and “Seven (more) deadly sins of microservices” (available in youtube.). They are very useful.

The interesting thing is that my current project really nicely suits to microservices architecture. We have several teams doing their own services. The services can run independently and they follow the main idea that “A microservice should be doing one thing, but in the best way!”. There will be pressure and scalability issues. Microservices architecture will help us solve these problems.

But there I have some thoughts about the way a current microservice should be implemented. This will be the subject for the next post.

And yes, train is a nice place to work. Especially if there is an A/C plug.

Oh, here is Sofia. It has beautiful renewed central station.