educative.io

Horizontally scaled monolith

" Distributed systems became mainstream with large-scale applications solely because, in them, we can eliminate the single points of failure that were a big downside of a monolithic architecture ."

Why can’t I have a horizontally scaled monolith with redundancy to ensure high availability? In case one monolith server failed another one takes over. But I have all my business logic at the same repo which is more convenient for a small team than have a range of micro-services for each feature.

Hello @Apolishchuk

Horizontal scaling, also known as scaling out, is the process of adding more instances of a component or application to distribute the workload across multiple machines or servers. In monolithic architecture, horizontal scaling can be challenging due to its tightly coupled nature. Here’s why:

  1. Inability to Scale Components Independently: In a monolithic architecture, all components are tightly coupled and run within the same process. Scaling out the entire application means replicating the entire monolith, including all its components. This lack of granularity makes it challenging to scale specific components that may require more resources while leaving others unchanged.
  2. Communication Overhead: In a monolithic architecture, components often communicate through in-memory function calls or shared memory. When scaling out, communication between different instances becomes more complex and potentially slower due to inter-process or network communication. This can introduce latency and performance issues.
  3. Data Sharing and Consistency: Monolithic applications usually share a single database or data store. When horizontally scaling, multiple application instances would need to access the same database, leading to potential contention and synchronization challenges. Ensuring data consistency and handling concurrent updates becomes more complex.
  4. Session Management and Stateful Components: Monolithic architectures often rely on session management and may have stateful components that store information about user sessions. Scaling out these stateful components across multiple instances requires careful consideration and potentially additional session synchronization or data-sharing mechanisms.

While horizontal scaling can be challenging with monolithic architectures, it’s not impossible. Some approaches that can help with scaling include:

  1. Load Balancing: Introducing a load balancer can distribute incoming requests across multiple instances of the monolith, helping with increased traffic. However, this approach doesn’t address the underlying challenges of scaling individual components.
  2. Vertical Scaling: Instead of adding more instances, vertical scaling (scaling up) involves increasing the resources (CPU, memory) of the existing machine or server hosting the monolithic application. This can help handle the increased load to a certain extent but has limits.

It’s important to note that one of the motivations behind alternative architectural patterns like microservices is to enable more effective horizontal scaling. By decomposing an application into smaller, loosely coupled services, each service can be independently scaled and managed. This provides more flexibility and scalability compared to monolithic architectures.

I hope this will help.
Happy Learning

1 Like