A monolithic architecture is the most used pattern for web applications due to its simplicity in development and deployment. Though the actual moving parts will differ from application to application, the general pattern remains the same. In general, a monolithic web application may do the following:
- It can support different clients such as desktop/mobile browsers and native desktop/mobile applications
- It can expose APIs for third-party consumption
- It can integrate with other applications over REST/SOAP web services or message queues
- It can handle HTTP requests, execute business logic, access a database, and can exchange data with other systems
- It can run on web application containers such as Tomcat, JBoss, and so on
- It can be scaled vertically by increasing the power of the machines it runs on or scaled horizontally by adding additional instances behind load balancers
REST (Representational State Transfer) relies on a stateless, client-server, cacheable communications protocol. HTTP is the most commonly used protocol for REST. It is a lightweight architectural style in which RESTful HTTP communication is used to transfer data between a client and server or between two systems.
SOAP (Simple Object Access Protocol) is a messaging protocol using HTTP and XML. It is widely used in SOAP web services to transfer data between two different systems.
An example of a typical monolithic web application architecture would be as follows:
Let's imagine an online hotel reservation system that takes reservation orders online from customers, verifies the room availability, verifies the payment option, makes the reservation, and notifies the hotel. The application consists of several layers and components including a client-side app, which builds a nice rich user interface, and several other backend components responsible for managing the reservations, verifying payment, notifying customers/hotels, and so on.
The application will be deployed as a single monolithic Web Application Archive (WAR) file that runs on a web application container such as Tomcat and will be scaled horizontally by adding multiple instances behind an Apache web server acting as a load balancer. Take a look at the following diagram:
The advantages of a monolithic web application architecture are as detailed here:
- Simpler to develop as the technology stack is uniform throughout all layers.
- Simpler to test as the entire application is bundled in a single package making it easier to run integration and end-to-end tests.
- Simpler and faster to deploy, as you only have one package to worry about.
- Simpler to scale as you can multiply the number of instances behind a load balancer to scale out.
- Requires a smaller team to maintain the application.
- Team members share more or less the same skill set.
- The technical stack is simpler and most of the times easier to learn.
- Initial development is faster hence making time to market faster.
- Requires simpler infrastructure. Even a simple application container or JVM will be sufficient to run the application.
The disadvantages of a monolithic web application architecture are as detailed here:
- Components are tightly coupled together resulting in unwanted side effects such as changes to one component causing a regression in another and so on.
- Becomes complex and huge over time resulting in slow development turnaround. New features will take more time to develop and refactoring of existing features will be more difficult due to tight coupling.
- The entire application needs to be redeployed for any changes.
- Is less reliable due to tightly coupled modules. A small issue in a service might break the entire application.
- Newer technology adoption is difficult as entire application needs to be migrated. Incremental migration is not possible most of the time. Hence many monolithic applications end up having an outdated technology stack.
- Critical services cannot be scaled individually resulting in increased resource usage as the entire application will need to be scaled.
- Huge monolith applications will have a higher start-up time and high resource usage in terms of CPU and memory.
- Teams will be more interdependent and it will be challenging to scale the teams.