Everything you need to know about Microservices
An article to understand the Microservice in a simplest terms
Microservice is a software development technique which aims to break down the components of the applications into smaller parts which are independent from each other and can work together. Breaking down the application components provide ease in development, increase code readability and also codebase becomes easy to maintain and test.
Why Microservices
To proceed further with Microservices, firstly understand what is the monolithic architectures.
Monolithic means composed all in one place. Monolithic is a traditional way of writing code which incorporates components of the software in a single container and these components are interconnected ,dependent and tightly coupled. In a tightly coupled architecture, each component and its associated components must be present in order to execute and compile successfully.
As you can see from the given image below, user interface, business logic and data interface all in a single codebase and this indicates that to maintain and test this codebase will not be easier.
Let’s understand this with an example
You are creating an E-commerce web application (like Amazon) which accepts orders from customers, verifies inventory and avail credits, and ships them. The application consists of several components including the user interface along with some backend services for checking credit, maintaining inventory and shipping orders.
The application is deployed as a single monolithic application. You can run multiple instances of the application behind a load balancer in order to scale and improve availability.
The image shown below is an example of E-commerce web application
This solution works perfectly until your E-commerce site not to be become large, once the application becomes large and the team grows in size, this approach has a number of drawbacks that become increasingly significant:
- Unreliable — Even if one feature of the system fails, then the entire system fails
- Unscalable — Applications cannot be scaled easily since each time the application needs to be updated, the complete system has to be rebuilt
- Blocks Continuous Development — Many features of the applications cannot be built and deployed at the same time
- Slow Development — Development in monolithic applications take a lot of time to be built since each and every feature has to be built one after the other
- Not Fit For Complex Applications — Features of complex applications have tightly coupled dependencies
- Overloaded IDE — the larger the codebase the slower the IDE and the less productive developers are.
Solution to the problem
Define an architecture that structures the application as a set of loosely coupled, collaborating services. This approach corresponds to the Y-axis of the Scale Cube.
Benefits of the microservice
- Highly maintainable and testable — enables rapid and frequent development and deployment.
- Loosely coupled with other services — enables a team to work independently the majority of time on their service(s) without being impacted by changes to other services and without affecting other services.
- Independently deployable — enables a team to deploy their service without having to coordinate with other teams
- Capable of being developed by a small team — essential for high productivity by avoiding the high communication head of large teams
Microservice vs Monolithic Architecture
Let’s take an use case of e-commerce site to better understand the difference
The main difference we observe from the above image is that all the features initially were under a single instance sharing a single database. But then, with microservices, each feature was allotted a different microservice, handling their own data, and performing different functionalities.
Conclusion
So it is clear from the above discussion that microservice technique of writing software solves the problem of code maintenance, code testing and also adding new features doesn’t affect the entire system. We can also minimise the system failures.
I hope you liked reading this article, you can also visit my website where I keep posting article regularly.
Subscribe my mailing list to get the early access of my articles directly in your inbox and Don’t forget to follow my own publication on Medium The Code Monster to polish your technical knowledge.
Know your author
Himanshu Verma has graduated from the Dr. APJ Abdul Kalam University, Lucknow (India). He is an Android & IOS Developer and Machine Learning & Data Science Learner, a Financial Advisor, and a Blogger.