What is Monolithic Architecture ?
Monolithic Architecture simple means - All resides in one place. The entirety of application resides in a single code base. There can be multiple modules associated with the application like - payments, listings and authentication. The code for all the modules follows a single tech stack, and resides in a single code repository.
Disadvantages
- Since, the code base follows a single tech stack, it lacks technological flexibility. Company will then have to hire individuals who works on the same tech stack. Plus, the cost of migration from one tech stack to other would be very high.
- A single deployment (CI/CD) pipeline will be used for all the modules, which essentially means that even if only 1 module changes, all modules will get redeployed.
- If company wants to scale up a single module, the entire application would then be forced to scale up, which might be inefficient at some places. Hence, Independent scaling is not possible in this architecture.
- Lots of dependence among modules in the code base. If a particular version of a dependency has been upgraded for one module, then the other module using that dependency will also get the upgraded version.
Advantages
- Such types of code bases, wherein everything is in a single place, is easier to develop, as everything follows a single tech stack.
- It is easier to manage as well as, again, everything is in a single place.
- Such type of architecture is ideal for small projects or teams.
What is Microservices Architecture ?
Microservices architecture came into picture to tackle the disadvantages of Monolithic Architecture, wherein, a separate codebase, a separate repository and separate deployment pipelines are maintained for separate modules. Many big companies, like Netflix in 2009 switched from a monolithic to microservices architecture.
Advantages
- Independent scaling is now possible since all modules have got their separate databases, and separate deployments.
- It has technological flexibility as different code base can have an entirely different tech stack.
- Different versions of the same dependency can be utilized by different modules, without forcing any other module to do the same.
Disadvantages
- Since, separate teams will be working on separate modules, management overhead will increase as all teams will require different management approaches.
- Such kind of architecture is very complex to set up.
- Total cost incurred may be high as compared to monolithic as all modules have got their own set of pipelines of development and deployment.
How do different microservices talk to each other ?
- Many such architecture uses synchronous communication via HTTP requests made by microservices to each other. Every module has got its own API Endpoint, which is used by other to make HTTP requests.
- Asynchronous communication with a message broker can also be used wherein, microservices communicate via messages which are sent to the message broker queue, who sends it to the correct microservice.
- Service mesh like Istio are more commonly used when microservices are maintained using services like Kubernetes.
Special note
When migrating from a monolithic to microservices architecture, there is no hard rule to determine which parts of the code base will be moved out to a separate code base. It really depends on the business needs and business requirements.
Microservices Architecture is not an ideal choice for small projects, as the cost overhead and complexities will far outweigh the advantages.