DEV Community

Shaurya Vardhan Singh
Shaurya Vardhan Singh

Posted on

Intro to Monolithic, MicroServices and Monorepo Architecture

For the past few years, there was a trend to move from monolithic architecture to microservices architecture. While this was a good decision as microservices have many advantages now companies are moving a step further and going to monorepo architecture. So let's dive into what these architectures are -

For this blog let's take a front end of an e-commerce site as an example. Now the frontend of the e-commerce site can be divided into two parts
1- Admin site for sellers to add and edit their products
2- Website for users to view and buy these products

We can further divide these sites by creating a different module for payments etc. But we will keep it simple for this blog.

So if we have both the admin site and website in a single repository it is known as monolithic architecture. This was the traditional way of making software but it came with pitfalls as both the websites are in the same repository it becomes quite hard to maintain the code.

To overcome this we moved to microservices architecture in which both the admin site and website are different repositories. This helped in maintaining the code as people could work independently on any service.

Desktop - 1

Microservices brought advantages but they brought drawbacks as well -
1- As mainly packages use the same modules this leads to increased size on disk. For eg - both the admin site and website use react now react will be installed in both node_modules.
2- In microservice as each service has its own repository we have to update the version for each update and track its effect on other microservices.

To solve these problems we moved to monorepo, In monorepo architecture both the admin site and website are microservices but in the same repository.

Lerna is a great tool to manage monorepo. It scans through package.json of each module in your repo and installs the common modules only once this leads to less disk space usage.
It also manages the version number for each module and updates them according to change in them.

So in monorepo architecture, we have benefits of both monolithic architecture as well as monorepo architecture.

Choosing the architecture also depends on company size so if you are starting now you can start with monolithic architecture as it has the least overhead and then gradually move to monorepo architecture.

Top comments (1)

Collapse
 
awesomeironman profile image
Cyrus Gracias

Great post buddy!
I always wanted to understand this terms and now I know 😀