Monolith and Microservices Architecture
Published: 2022-09-05 15:31:27

## Monolithic architecture
 In software engineering, a monolithic pattern refers to a single indivisible unit. The concept of monolithic software lies in different components of an application being combined into a single program on a single platform. Usually, a monolithic app consists of a database, client-side user interface, and server-side application. All the software’s parts are unified and all its functions are managed in one place. 

![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/779bfyxcdi9txlu4w31j.png)

Сomponents of monolithic software are interconnected and interdependent, which helps the software be self-contained. I believe that a monolithic architecture is a perfect solution in some circumstances.

## Pros of a monolithic architecture
**Simpler development and deployment**
 In addition, all actions are performed with one directory, which provides for easier deployment. 

**Fewer cross-cutting concerns**
It’s easier to hook up components to these concerns when everything runs in the same app.

**Better performance**
If built properly, monolithic apps are usually more performant than microservice-based apps. An app with a microservices architecture might need to make 40 API calls to 40 different microservices to load each screen, for example, which obviously results in slower performance.  Monolithic apps, in turn, allow faster communication between software components due to shared code and memory.

## Cons of a monolithic architecture
**Codebase gets cumbersome over time**
In the course of time, most products develop and increase in scope, and their structure becomes blurred. The code base starts to look really massive and becomes difficult to understand and modify, especially for new developers.  It also gets harder to find side effects and dependencies. With a growing code base quality declines and the integrated development environment (IDE) gets overloaded.

**Difficult to adopt new technologies**
Adding new technology means rewriting the whole application, which is costly and time-consuming.

**Limited agility**
In monolithic apps, every small update requires a full redeployment. Thus, all developers have to wait until it’s done.  When several teams are working on the same project, agility can be reduced greatly.

## The bottom line
Monolithic software architecture can be beneficial if your team is at the founding stage, you’re building an unproven product, and you have no experience with microservices. Monolithic is perfect for startups that need to get a product up and running as soon as possible. However, certain issues mentioned above come with the monolithic package.

## Microservice architecture
Microservice is a type of service-oriented software architecture that focuses on building a series of autonomous components that make up an app. Unlike monolithic apps built as a single indivisible unit, microservice apps consist of multiple independent components that are glued together with APIs.

![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/za7c31041xvimddadi8d.png)

Microservices are important simply because they add unique value in a way of simplification of complexity in systems. By breaking apart your system or application into many smaller parts, you show ways of reducing duplication, increasing cohesion and lowering your coupling between parts, thus making your overall system parts easier to understand, more scalable, and easier to change.

## Pros of microservices
**Easy to develop, test, and deploy**
The biggest advantage of microservices over other architectures is that small single services can be built, tested, and deployed independently. Since a deployment unit is small, it facilitates and speeds up development and release. The last plus here is that the risks of deployment are reduced as developers deploy parts of the software, not the whole app.

**Increased agility**
With microservices, several teams can work on their services independently and quickly. Each individual part of an application can be built independently due to the decoupling of microservice components. For example, you may have a team of 100 people working on the whole app (like in the monolithic approach), or you can have 10 teams of 10 people developing different services for the app. Let’s imagine this visually.

![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/t72zca5gy55911abv1wb.png)

Increased agility allows developers to update system components without bringing down the application. Moreover, agility provides a safer deployment process and improved uptime. New features can be added as needed without waiting for the entire app to launch.

**Ability to scale horizontally**
Vertical scaling (running the same software but on bigger machines) can be limited by the capacity of each service. But horizontal scaling (creating more services in the same pool) isn’t limited and can run dynamically with microservices. Furthermore, horizontal scaling can be completely automated.

## Cons of microservices
**Complexity**
Splitting an application into independent microservices entails more artifacts to manage. This type of architecture requires careful planning, enormous effort, team resources, and skills. The reasons for high complexity are the following:
- Increased demand for automation, as every service should be tested and monitored
- Available tools don’t work with service dependencies
- Data consistency and transaction management becomes harder as each service has a database

**Security concerns**
In a microservices application, each functionality that communicates externally via an API increases the chance of attacks.  These attacks can happen only if proper security measurements aren’t implemented when building an app.

**Different programming languages**
The ability to choose different programming languages is two sides of the same coin. Using different languages make deployment more difficult.  In addition, it’s harder to switch programmers between development phases when each service is written in a different language.

## The bottom line
Microservices are good, but not for all types of apps. This pattern works great for evolving applications and complex systems.  Consider choosing a microservices architecture when you have multiple experienced teams and when the app is complex enough to break it into services. When an application is large and needs to be flexible and scalable, microservices are beneficial.

Monolithic apps consist of interdependent, indivisible units and feature very low development speed. Microservices are very small, loosely coupled independent services and feature rapid continuous development.