Table of contents
- But what is a Microservice?
- Monolithic Architecture
- Here comes Microservices!
- Why should we care about Microservices?
- Omg you're so excited to jump into Microservices!!!!!
- But still you want to deep dive into Microservices right?!
- Come on, just tell us the Techstack!
- Any good recommended project ideas?
- Conclusion
Microservices are everywhere! From emerging startups to industry giants, microservices play a vital role in the technical industry of today's age. Aspiring developers have started putting their heads into this ocean of opportunities!
This guide is for those aspiring developers with basic understanding of development in general, or those who are interested to learn about microservices in general.
DISCLAIMER: This post is not intended to go deep into the implementation details of microservices. But of course, it is in the list for the near future!
But what is a Microservice?
Wikipedia gives a good definition of microservice. According to wikipedia,
A microservice architecture – a variant of the service-oriented architecture (SOA) structural style – arranges an application as a collection of loosely-coupled services.
I know I know, it is kinda hard to get a good understanding of it from this definition though it explains the topic properly. That's why this post is here right!
But before explaining Microservices, let me start with it's predecessor, Monolithic Architecture, with a very good reason.
Monolithic Architecture
Monolithic architecture is one of the most traditional way of building an application where each and every service/resource is built as a single unit. In another words, every feature is packed in a single application. This approach of building application is considered to be straightforward and easier to implement as we, as engineers, have complete control over the whole application.
Then why Microservices then? Why are we moving from monolithic architecture to microservices? There is are some good reason behind this.
- As monolithic architectures have all the features required to run the application as a single unit, the code base generally tends to become huge and lack modularity.
- Scaling a monolithic architecture comes with a lot of problems as you have to scale the whole application and cannot scale the individual components such as database, server instances etc.
- Modification to one service/feature may affect the whole system, even causing the whole system to go down, because of tightly coupled nature of it. Ahh! you cannot afford that man!
- Flexibility is very hard to introduce. Some services work better with SQL relational databases, where some other services takes good advantage of NoSQL patterns. Introducing two types of databases for one single monolithic application doesn't seem feasible right?
Here comes Microservices!
While learning algorithms in Computer science, or any domain where breakdown of problem is needed, one of the best algorithm out there is the Divide and Conquer! Microservice architecture wants to follow the method to solve the issues with monolithic arthitectue and scale your application to the moon!
Microservice architecture follows the philosophy of Divide and Conquer. Here, your application is divided into independent individual units carrying out an entire application process for that particular service/feature only, with their own database! It is hard to get a grasp at first but trust me! This is how you post videos on youtube, watch reels on Instagram, or study in online course providers.
In Microservice architecutre, You can consider each service as an independent application running without depending much upon other services.
For some reason, if a service gets crashed during runtime, it'll not affect the entire application and the crashed service can be restarted with one single docker or kubernetes command (not really) without any downtime of your application.
Why should we care about Microservices?
- Microservices are independent components, which makes them quite easy to deploy and updated independently, giving better flexibility compared to monolithic architecture.
- Hey, one tiny "undefined" error should not take your entire application down right?
Developing the application in teams is much easier as each service is seperate application and is allowed to use their own tech-stack! Whoah!
Scalling is just mindblowingly simple, with amazing power of containerization and Kubernetes.
Cloud-Native application is mostly based on Microservices!
Omg you're so excited to jump into Microservices!!!!!
Wait!! Before jumping into this rabbit-hole, take a break and get a good understanding of some of it's weaknesses as well.
Microservices introduce extra complexity and a lot of boilerplate codes to setup individual databases, modules, server instances etc. to be deployed independently.
Synchronisation and communication between two different services and data flow is THE PROBLEM of microservice architecture and follows some "weird" ways to solve the problem.
Microservices are hard to understand!
But still you want to deep dive into Microservices right?!
That's the spirit!
So getting into microservices takes a good understanding on the design principles of microservice architecture. Some basic principles are mentioned below.
A single microservice unit has only one problem to solve and takes into account the problem that it is supposed to without thinking or taking consideration of other services. This is the backbone of microservice architecture. For example, there should be no possibility of accessing student information during authentication response.
A single microservice has clear boundaries and should be made discrete in nature. That's why containers such as Docker and orchestration tools like Kubernetes is so much useful while creating a microservice. This also allows microservices to use different techstack for development of microservices.Theoretically, it is possible to use single microservice to use in different application as well.
Chaning runtime environment of microservices should be easier, hence it should be transportable.
Microservices has their own database which is isolated from other microservices.
Come on, just tell us the Techstack!
Well, you can use any techstack to develop a microservice! That's the beauty of it!
If you're a Javascript starter, then it is recommended to go with Express.js ofcourse.
For Typescript professionals, NestJS is amazing framework for developing microservices and they have amazing documentations!
For Pythonistas, Django is the way to go.
I can go a long way just listing the techstacks but that's why our friend Google is there right.
Any good recommended project ideas?
TODO!!!
Seriously, developing a super simple Todo application becomes tricky in microservice architecture, for beginners at least!
Therefore, it is recommended to start with some basic yet fully implemented Todo or Blog app that you can do to get a good understanding of Data Syncronisation and other very important concepts of Microservice architecture.
Also, you can find some amazing open-source cloud-native applications hosted in github. It really helps alot to engage in community and get their help to understand the projects, which will give you a good understanding of large codebases.
Conclusion
The domain of microservices is really an ocean of opportunities and really opens the door to introduce yourself to the world of Cloud Native applications. I think, learning devops along with microservice architecture in 2022 is one of the best thing that you can do!