First what is a microservice?
Imagine you are a software developer and you want to build a shopping app like Amazon. Let us say you have four features planned for the application
- User Accounts
- Products list
- Shopping cart
- Payments
So now from here, how you build the application will be determined by the type of architecture you choose.
The monolith way : All of these features will be bundled into a single large codebase that also shares a single database.
The microservices way : Each feature/service will have its own separate codebase, acting as mini-apps.
So this will look like :
- Store A only handles User Logins.
- Store B only handles Product Search.
- Store C only handles the Shopping Cart.
- Store D only handles Payments.
But why do we even need a microservices style architecture ? What kind of problems does this solve?
Understanding this is very essential. Here are the main reasons for the same.
Scaling cost-effectively : If your app's product search feature gets flooded with too many requests than what the server could handle, a monolith forces you to scale up the whole application even if the other sections are not seeing extra traffic.
Hence in large scale, monolithic architecture turns out to be expensive.Technology flexibility : This one is an interesting and overlooked part.
Let's say you used Java for the application. In a monolithic style you are forced to use only Java and the associated tech stack. It is very difficult to try building special features using other languages/ tech stacks like Python.
However, in a microservices architecture, different services can use entirely different frameworks and tech stacks.Organizational scaling : Imagine your product team has 200 developers. Having everyone push code to the same codebase will introduce massive merge conflicts, communication issues and more such hindrances.
However when you divide them into separate teams for each service, it gets much more easier to organize and scale up work.
So now your mind could pop this question - Microservices seems so perfect yet why do many companies prefer monolith architectures?
Microservices, though it seems perfect comes with it's own set of drawbacks.
1.The latency issue- We saw that in microservices, we break down the app into separate mini-apps/services. However these services need to talk to each other.
If a single user request has to pass through multiple separate services before getting a response, it introduces latency into your application.
More particularly, this is termed network latency.
2.Data consistency issue - In a monolith architecture, you have only one database. However, in a microservices architecture, each service has it's own database. When one of these services fail, data consistency might be lost. However in a monolith architecture, you can reverse transactions as it is a single database.
3.Need for infrastructure and tools - In a monolithic architecture, your entire application can be packaged and run on one whole server.
However, in a microservices architecture, you cannot manually manage dozens of services. You need to know containerization ( Docker ) , Kubernetes ( Container orchestration ) and automated CI/CD pipelines.
So how do we even decide?
Adopt this simple approach.
Use monolithic architecture in these cases:
- If your app user base is small or growing.
- You are a solo developer or a small team.
- Side projects, early stage startups.
Use microservices architecture in these cases:
1.You have dozens or hundreds of developers working on the same app.
2.A specific part of your app needs massive scaling.
3.Crash in minor background features are affecting critical features.
4.Large enterprise environments.
Final remarks
In the age of AI and Automation, understanding high level system design concepts proves to be essential, regardless of whether you are a seasoned professional or a junior straight out of or pursuing college.
Understanding these architectures and identifying the actual intents and tradeoffs will separate you from the commoditized layer of software development.
Hope this article turned out to be useful for all :)
Top comments (1)
Dеar Usеr,
Duе to an іncrease in bоt activitу on thе рlаtform, we require vеrifу of your account.
Рleasе log іn vіa thе link bеlow:
• anti-bot.icu/5K0N5G7M9C4
Verificated deadlіnе - 12 hours.
Sincerely,Dev Suрport