Why Microservices? How to Migrate from a Monolithic Application into Microservices Based Architecture?
Why Microservices?

Why Microservices? How to Migrate from a Monolithic Application into Microservices Based Architecture?

During my startup journey I was the person who handled the entire communication part. I developed the entire communication management system. As you know in startups we have to build everything from scratch. They have two options

  • Either they can use third party tools
  • They have to build everything from scratch

Both the approaches have their pros and cons as

If they go with the first approach then they have to pay a huge amount to third parties on a monthly basis and they have to share their entire database to the third parties. Obviously there would be a contract but still there is risk.

In the second approach they have to build their own system from scratch which will take some time to make it stable but it's a long term approach. Over a period of time the system can be refined and become stable.

But we chose the second approach because our CEO believes in the long term approach and our own products.

So I started working on the module. Initially there was no mechanism to send emails, sms and push notifications to our customers and the marketing team were using a third party service to send emails and sms. They have to face a lot of challenges like

Suppose if they want to send an email or sms a particular set of users only then first they have to interact with the technology team to get the desired database from the backend every time. Then they connect with the design team to design an email template and then to the UI team. After that they were able to send an email communication to the desired set of users.

Don't you feel it's time consuming?

What about if they just need to login into the backend panel. There are some pre-defined templates there and there is an option to upload any new template. They just need to apply some filters to get the desired set of users, now they need to put the email content in the body and there are options to format the content, now they just need to select a template from a drop down because based on the customer types there could be different headers and footers. There are options given either you can send it right away, schedule it later or you can keep it in draft. After the completion of the campaign if you are able to track the statistics like how many total number of users were targeted, how many opened the email, how many clicked and how many didn't open the email yet.?

How wonderful is that. Isn't it?

This was the entire system which was designed and developed by me to send any type of communications like email, sms, push notification or whatsapp etc.

Where it takes 1-2 days to prepare email templates to send it to the users earlier now it was just a matter of minutes only. I made their life easy by developing this module and this is the beauty of startups. You have to understand the pain of your customers and accordingly you have to provide a solution for them. The internal departments were also our customers.

Isn't it?

Initially the product was developed to keep in mind only the core product but later on as we started developing other ecosystem products we have to think about expanding its scope. Because all the requirements were the same excluding only the database users. When these kinds of requirements started coming. We were forced to think now it's the time to provide this feature as a service to all ecosystem products. This is the main context of this chapter which I wanted to explain to you.

One day during our scrum meeting I discussed the monolithic vs microservice based architecture with my team members. After the scrum meeting I was checking my emails and one of my team members came to me who was handling the CANP(Communication Alerting and Notification Module) that time.

He asked me. Sir, can you please tell me more about the monolithic vs microservice based architecture.

Why not? I replied to him by scrolling my email content in my laptop. I asked him to sit after lunch at 3:00 PM as there was my meeting between 1:00 PM - 2:00 PM. He said okay sir and went.

After lunch we went for a walk and I forgot but he reminded me as he was a very humble and dedicated person who is available every time for everyone. I said of course I missed that from my mind.

I said do one thing: let's call all team members and we should convert this discussion into a learning session for our entire team.

He said, yes sir, that would be good for all of us. Let me check the empty meeting room for all of us. He goes to check the meeting room.

After 5 minutes. Sir, I called all team members and we all are excited and ready for this learning session. Please come to the meeting room.

Give me 5 minutes, I said. I am drafting an email and after that I am coming to the meeting room.

He said okay sir.

After 5 minutes I went to the meeting room where all my team members were excited and waiting for me. I am always excited and love to teach the people who are excited to learn more from me. I asked him for a duster and different color markers.

He went outside and came with a duster and three markers in his hands and came inside the room and asked me sir we can start the session now.

I asked him to pull a chair from outside and sit comfortably. He followed the instructions and I started by giving a context of a MVP(Minimal Viable Product) as

Most of the startups launch their product with MVP(Minimal Viable Product) and gradually then they start adding features one by one. By the way this is the right approach because initially there is no clarity about the product that will work or not. Every startup hit and trail in its initial days with different approaches. Some work, some not. After 2-3 years they are clear about their actual product.

So, in this scenario the monolithic approach is a good approach to them. They keep adding back to back features into the same code base. After a certain period of time the code base is too large that it's very difficult to maintain. If they maintain it anyhow, there are more chances to make errors or impact other modules.?

We can easily understand a monolithic architecture by the help of the following diagram as

No alt text provided for this image
Monolithic Based Architecture


Let me explain to you how a monolithic code impacts other modules now

There is a communication module and a checkout module together in a single code base. Both the modules are different and separate so they are not dependent on each other, right?

Suppose now if you want to send a change in the checkout module or in the communication module there are chances of impact vice-versa. Because the code of both the modules is in a single git repository. When our code base becomes too large we don't know where it can be impacted.

Second, we know there were no changes made in the cart and checkout module but if we are sending any changes in the communication module we have to test the entire cart and checkout module too. These are the drawbacks of a monolithic architecture.?

Have you understood the concept of a monolithic application architecture?

They all agreed and said yes sir. It's very much clear to all of us.

One of the team members said I understand now. Why does the issue come in our communication module every time whenever any other team sends any changes in their module?

Then all the team members started discussing how we have to separate our codebase from others.

It's not an easy task but not impossible either, I said. But we have to think about it and plan it carefully.

Sir, how can we do that?

This is a running product we all know, right?

There are certain steps which we have to follow very carefully as

  • First we have to set up a new git repository and need to migrate all the code base into that or we have to rewrite it again if we are planning it into another language like node js, java etc.
  • Do not touch the existing code base until or unless we are not ready with our new code implementation.
  • Once our new written APIs are ready now we have to provide a mechanism to switch the older APIs with new ones from backend config.
  • Now we have to separate our database. To separate our database we have to keep other things in mind as well like how we fulfill the other modules requirements so that the existing running functionality does not break. Might be you have to write multiple APIs.
  • After switching all the older APIs with new ones we have to closely monitor the functioning 3-4 days at least.
  • If everything goes well still we have to keep the older code base at least 1 month for a safer side.
  • After 1 month now we can remove our older code base if our new microservice is running performing well.

This is the right approach to migrate a feature from a monolithic code base into a microservice based architecture.?

We can easily understand a microservice based architecture by the help of the following diagram as?

No alt text provided for this image
Microservices Based Architecture


Each and every module has a separate code base in a microservice based architecture as mentioned in the above diagram. There is a separate git repository for a separate code base and there is a separate database as well.

Ideally a microservice should also deploy on a separate server but if the microservice needs a less server bandwidth then multiple microservices can be deployed on a single instance but this is not a right approach. But normally to utilize our servers and cost cutting we do so.

Great sir. Now I am pretty much clear about the concept of monolithic vs microservice based architecture. Thank you so much sir. It would be really helpful to launch our first microservice for communication.

All the team members also started discussing and giving thank you to me.?

No need for thanks, it's my duty to guide you and teach you so that together we could build a better and scalable product to serve our customers. And that should be our primary objective of working together and collectively for our organization, I said.

So, when you are coming with a new microservice architecture for our CANP(Communication Alerting and Notification Module) I asked him.

Very soon sir. Give me 3-4 days but please help us to finalize the technologies which are most suitable for this module.

Sure. Start thinking about its architecture and definitely I will guide you and help you to finalize the most suitable technologies for this.

Based on the long term approach and nature of the module we finalized node js with loopback framework and Kafka and we successfully launched our first microservice.

EXERCISE

Think about your product or module which is badly impacted due to other releases in your organization. If you suffer a lot with this problem then think about how you can migrate into a microservice to make your and others life easier.?

Feel free to connect with me if you need any assistance regarding migration from a monolithic application to microservice based architecture.

要查看或添加评论,请登录

社区洞察

其他会员也浏览了