Choosing the right architecture is critical for the overall success of your product. The three most popular architectures used in the IT world are Monolith, Microservices, and Serverless. Each one offers its own advantages to create exactly the right sort of solution for your users with the best possible experience. Let’s take a look at each architecture separately to see how they work and uncover potential benefits.
Monolithic software is self-contained and all of the various components are interconnected with each other. This means that each component and all of the components associated with it need to be present for the code to be executed and compiled. If you would like to update even one of the components, this means that you will need to rewrite the entire application. While this scares away a lot of developers from creating monolithic architectures, it offers substantial benefits as well such as:
- Less issues affecting the entire app – These include error handling, logging and caching. All of these functionalities would only concern a single app thus making life simpler.
- Simpler testing and debugging – the monolith is a big cohesive unit, thus making it possible to perform end-to-end testing faster.
- Easy to deploy – Since there is only one file or directory only one deployment is necessary.
While the monolithic architecture may charm some developers with its simplicity, things could get very complicated if and when you decide to scale. As the monolith scales up, things get hairy very quickly since any complex system of code with only one app will be difficult to manage. Additionally, the following factors will need to be considered with a monolithic architecture:
- Making changes – It will be difficult to make even small changes because everything is interconnected. In other words, even a small change can reverberate across the entire application.
- Scalability – Independent components cannot be scaled
- Obstacles for new technologies – If you would like to introduce any new technology into the monolith, you will have to rewrite the entire application.
Since developing in a monolithic architecture presents so many difficulties, companies have decided to use a microservices architecture instead. Let’s take a look.
The microservices architecture breaks down each individual component into separate units which carry out the application processes as a separate service. Each service has its own logic and database. Think of it as creating one application with a suite of smaller services. The functionality will be divided among these smaller services, which can be deployed independently, and communicate with each other via API. In addition to everything mentioned above, the following are additional benefits offered by the microservices infrastructure:
- Flexibility – Enjoy added flexibility as far as technology is concerned and being able to add new features and services along the way.
- Enhanced scalability – Scale each component independently without worrying about reaching a ceiling. This means you will be able to accommodate more users quickly without making any drastic changes.
- Increased agility – Any issues found in the microservices architecture will only affect one service instead of the entire app. This means that any new changes that you implement will involve less risk.
While it may seem that microservices is the ideal infrastructure, it does come with its drawbacks as well:
- More complex – In a distributed system, you have to create the connection between all databases and modules,
- Testing – Since the microservices architecture consists of several components each of which can be deployed separately, testing becomes much more difficult.
- Cross-cutting concerns – These issues include externalized configuration, logging and other issues.
While monolithic and microservices architectures have been traditionally used for creating applications, recently a new one has emerged called serverless.
The term “Serverless” was first used to describe an app that either mostly or fully used third-party, cloud-hosted apps and services to manage the back-end logic. However, this term can also refer to an instance where the logic on the server-side is still written by a human, but it is being run with stateless compute containers. A popular term that is being used to describe this architecture is Functions as a service (FaaS).
Businesses take advantage of cloud services from AWS and Microsoft Azure to replace physical servers. There is no need to provision or manage servers which saves you a lot of money on overhead costs associated with actually running the servers, storage space and salary for system administrators.
Additional benefits of serverless include:
- Less time to market – A new app can be created in a matter of hours. There are lots of apps on the market today that rely on vendor APIs such as OAuth, Twitter, and Mapbox.
- Scalability – With a serverless architecture you do not need to provision infrastructure for emergency scenarios. Scaling is performed automatically and seamlessly.
- It’s on whenever you need it – If you are experiencing a sudden surge in users, you will be able to accomodate them with on-demand computing prower. This means you do not have to provision any resources for unexpected situations.
The disadvantages of the serverless architecture are:
- Problems resulting from third-party APIs – these problems include vendor control and lock-in.
- Less operational tools – You are totally dependant on the vendor for your debugging efforts. Also, to perform a thorough search for bugs and to uncover the underlying problem, you will need to have access to all kinds of metrics which might not be easy to get.
- Implementation is a problem – Integration testing serverless apps is very difficult. Smaller integrational units mean that you will be relying on integration testing more so than with microservices or monolithic architectures. Now that we have an idea of each type of architecture, let’s take a look at when it would be best to use each one.
Which One to Choose?
Microservices are very popular right now, but it would be a mistake to use it just because other people have adopted it. There have been many situations where companies tried to adopt microservices, but due to a lack of knowledge, ended up creating something that was neither a monolith nor microservices. They have services that are not properly encapsulated and one service was connected to another in a way that one agile team could make an independent decision on deploying a microservice.
Therefore, it is a good idea to start with the monolithic architecture, especially if you do not have any microservices experience. Also, if you are at the founding stage and have a team of five people or less you should also stick with the monolithic architecture because you will not be able to handle the high overhead of microservice. If you are developing a new product that is unproven on the market, chances are that it will evolve over time so a monolith would be well suited for you since it allows for fast product iterations.
The microservices architecture will be a good fit if you need fast and independent service delivery. However, you should know that it might not see gains in delivering your service right away. Also, if a certain part of your platform needs to be more efficient than others, microservices will be ideal because it allows for independent scalability and increased flexibility.
If you have a certain operation within your system that takes up a significant amount of computing power with unpredictable spikes in traffic, it is a good idea to use a serverless architecture. If you are already using microservices, then the system is likely prone to further decoupling, but it serverless could still make sense if you are using a monolith as well. However, if you are not currently on the cloud, you should not start with serverless. Services like AWS Lambda work best when combined with other services from AWS. If you are not ready to lock your service into a specific vendor, then serverless is not right for you.
Making the Decision
Software development itself is a process, therefore you need to clearly understand the problems that you are facing and how you plan to deal with them. This is necessary even before you start considering your choice of architecture: Monolith vs Microservices vs Serverless. Think about the patterns that fit the problem and the scale you need the app to perform. Try not to get too caught up in the details such as the programming language you will use. Instead think about your estimated time to market, the size of your team and the deadlines.
It is important that you not rush the decision of your architecture and get inputs from lots of different sources. After all, transitioning to a new architecture will be time consuming and expensive.