DEV Community

Cover image for Monolithic vs Microservice
Lawson
Lawson

Posted on

Monolithic vs Microservice

Microservice

MICROSERVICES_Logo.png

Monolithic Architecture

A monolithic design refers to software that is built and deployed as a signle unit, called a monolith. A monolith usually consists of a user interface, a server-side application and a database.

The concept behind monolithic software is that different parts of a system are closely tied together, such as in a monolith, this system is called to exhibit tigh coupling.

Monolithic Application

This architecture has a number of benefits:

  • Simple to test and deploy
  • Easy scaling by running multiple copies behind a load balancer.
  • Perfomant and low latency. Requests are served from a signle unit which means the request path contains few network hops and components.

Monolithic Hell

  • Overwhelmingly Complex

Applications are software systems that tend to grow over time, accumulating more and more functionality. As a result, they often become huge and difficult to comprehend, even for experienced developers. This can make fixing bugs and implementing new features a daunting task that requires a significant amount of time and effort.

  • Larger apps take longer to start up.

Larger apps, with more complex features and functionalities, require more time to start up. This can be due to a variety of factors, such as larger amounts of data to load, more complex algorithms to run, or more resources required to manage the larger app. If we have to regularly restart the application server, it causes a large part of the day to be spent waiting around, and productivity suffers. In addition, it is important to consider the impact of such downtime on clients and customers who may be relying on the application for critical business functions. Extended downtime may result in lost revenue, missed deadlines, and a negative impact on the company's reputation. Therefore, it is essential to implement measures to minimize the frequency and duration of server outages, such as regular maintenance and updates, load balancing, and failover systems.

  • Reliability

When a software application is composed of multiple modules running within the same process, it is important to consider the impact of bugs within these modules. One such bug that can have significant consequences is a memory leak. If a memory leak is present in any of the modules, it can gradually consume more and more memory, eventually causing the entire process to crash.

  • Extremely difficult to adopt new frameworks and languages.

Microservice

A microservice is a software development technique that structures an application as a collection of small, independent services that work together to accomplish a larger goal.

A service typically implements a set of distinct features or functionality, such as order management, customer management, etc. Each microservice is a mini-application that has
its own hexagonal architecture consisting of business logic along with various adapters.

Some microservices would expose an API that’s consumed by other microservices or by the application’s clients. Other microservices might implement a web UI. At runtime, each instance is often a cloud virtual machine (VM) or a Docker container.

Untitled Diagram.drawio (1).png

Benefits and drawbacks

Benefits

It tackles the problem of complexity.

  • It decomposes what would otherwise be a monstrous monolithic application into a set of services.
  • While the total amount of functionality is unchanged, the application has been broken up into manageable services.
  • Individual services are much faster to develop and much easier to understand and maintain.

Independence

Untitled

  • The developers are free to choose whatever technologies make sense.
  • When writing a new service, they have a option of using technology. Moreover, since services are relatively small. it becomes more feasible to rewrite the old service using current technology.
  • At runtime, each service is often a cloud virtual machine (VM) or a Docker container.
  • the Microservices Architecture pattern enables each service to be scaled independently.

Easy to deploy

  • Developers never need to coordinate the deployment of changes that are local to their service
  • These kinds of changes can be deployed as soon as they have been tested.

Drawbacks

One drawback is the name itself.

The term microservice places excessive emphasis on service size. In fact, there are some developers who advocate for building extremely fine-grained 10-100 LOC services. While small services are preferable, it’s important to remember that small services are a means to an end, and not the primary goal. The goal of microservices is to sufficiently decompose the application in order to facilitate agile application development and deployment.

A microservices application is a distributed system.

Developers need to choose and implement an inter-process communication mechanism based on either messaging or RPC. Moreover, they must also write code to handle partial failure, since the destination of a request might be slow or unavailable. While none of this is rocket science, it’s much more complex than in a monolithic application, where modules invoke one another via
language-level method/procedure calls.

The partitioned database architecture.

Business transactions that update multiple business entities are fairly common. These kinds of transactions are trivial to implement in a monolithic application because there is a single
database. In a microservices-based application, however, you need to update multiple databases owned by different services. Using distributed transactions is usually not an option, and not only because of the CAP theorem.

Implementing changes that span multiple services.

For example, let’s imagine that you are implementing a story that requires changes to services A, B, and C, where A depends upon B and B depends upon C. In a monolithic application you could simply change the corresponding modules, integrate the changes, and deploy them in one go. In contrast, in a Microservices Architecture pattern you need to carefully plan and coordinate the rollout of changes to each of the services. For example, you would need to update service C, followed by service B, and then finally service A. Fortunately, most changes typically impact only
one service; multi-service changes that require coordination are relatively rare.

Top comments (0)