Shifting From a Monolith To Microservices - Is It Worth It?

The term microservices is a rising topic these days. Even more trending is the debate on whether you should use a monolith or microservices. Let's find out together!

most of the big and successful applications which exist today were started as a monolith, but in the last few years, more and more (big) companies slowly switch to a microservice environment. But why? And what do these terms actually contain?

What is a monolith?

As the name implies, a monolithic application consists of one system, where parts such as the codebase, business logic, and other parts are all interconnected and dependent on one another. The Monolith will be responsible for all traffic, data-access and more. It has access to databases, all the application logic is in one place and it even takes care of external application integration, like REST APIs or distributes data through API endpoints. As you may have noticed, a monolith is a centralized architecture. Monoliths are known to be simple to develop, test and deploy, due to it's centralized nature.

Drawbacks
With benefits come drawbacks. As a monolith is a whole project on it's own, it needs some time to redeploy it whenever there needs to be a change in the code. Furthermore, when you make a code change, you have to keep other services inside your monolith in mind, as your code can break because services are closer to each other. The same can be said about code errors. Microservices largely prevent that. When there's a significant strain on the application, but only on, say for example, the payment service, you can't increase hardware specifications on that service. You need to upgrade hardware for the whole monolith or make the application redundant with a second running server.

What are micro services?

Microservices are split-up services communicating with each other to form an application. E.g.: A website runs on a single server as a monolith. The website gets more visitors. Many more people visit and it gets heavier for the server to keep accepting requests from so many users at the same time. You put another server next to it to balance the pressure until it happens again and again. Not very efficient. But what if I told you it could be easier. Microservices is a method of developing software  that tries to focus on building single-function modules, or services. A service can be developed without necessarily/directly affecting others and has many benefits for agile teams. It can combat system strain and overloading and can be more lightweight to deploy, because of it's split-up nature.

Drawbacks
On the other hand, It is much easier to have breaking changes in microservices compared to a monolith. Take variables as a quick example. If you change a variable in a service that needs to communicate with the API, communication might not work as intended anymore and it will be harder to notice this. Variables in a monolith are direct and easier to notice when there's a wrong function call. If you want to do it right, you also want to make sure every service has their dedicated datastore, because you need to make sure that there's a single responsible source of data for a single service.

When do you switch from a monolith to microservices?

In a popular case, you move to microservices when your team has scaled. When you have a large team and each and all of them want to move about individually, you'll create different teams for different services. To put it bluntly, a small team might have more advantages with a monolithic architecture.
Next, it is also wise to think about switching methods when you're having trouble with redundant servers, or bottlenecks on certain functions in your application.

Conclusion

Microservices can greatly increase speed and reliability in multiple ways with large and complex applications. It is more comfortable for bigger teams when services are independently editable and deployable and makes it all the more worthwhile to create or switch to a microservice architecture. Monoliths with their centered codebase are perfect for small-scale teams and applications are often easier to develop in these circumstances.


Sources

Monoliths vs. microservices — benefits and drawbacks [a comparision]
What to choose as a system architecture? Monolith or microservices? What is better for our company? Focusing on microservices architecture…
What are Microservices?
Microservice architecture, or simply microservices, is a distinctive method of developing software systems that tries to focus on building single-function modules with well-defined interfaces and operations. The trend has grown popular in recent years as Enterprises look to become more Agile and ...