System architecture ‐ Why monolithic? - JU-DEV-Bootcamps/ERAS GitHub Wiki

What is Monolithic architecture

Monolithic architecture is a software design paradigm in which an application is built as a single unified unit. In this architectural style, all components of the application—such as the user interface, business logic, and data access layers—are tightly coupled and run as a single process. An associated meaning of the core word “monolith” relates to the fact that its substance is all of one piece, making its composition completely uniform. Example of Monolithic architecture

This approach contrasts with distributed architectures, such as microservices, where the application is divided into smaller, independent services.

Key Characteristics

  1. Unified Codebase: All the components of the application share a single codebase and are deployed together.
  2. Tightly Coupled Components: Each part of the system is interconnected, making the application function as a cohesive whole.
  3. Single Deployment Unit: The entire application is packaged and deployed as a single executable or file.
  4. Centralized Data Storage: Typically relies on a single database to manage and store data.
  5. Vertical Scaling: Scaling is achieved by increasing the resources (e.g., CPU, memory) of the server hosting the application.

Advantages and Challenges of Monolithic Architecture

Starting with the advantages:

  1. Simplicity: Development and deployment processes are straightforward since all components are part of a single application.
  2. Ease of Testing: Testing is simplified as the entire application can be tested as a single unit.

However, the challenges associated are:

  1. Scalability Constraints: Scaling can be limited by the server’s hardware capabilities.
  2. Limited Flexibility: It’s challenging to adopt new technologies or modify individual components without impacting the entire system.
  3. Deployment Risks: A change in one part of the system may require redeploying the entire application, increasing the risk of introducing new bugs.

Comparison with alternatives

Microservices architecture is an alternative to monolithic architecture, where the application is divided into smaller, independent services that communicate over a network. Each service typically handles a specific business function and can be developed, deployed, and scaled independently. Example of Microservices architecture

Key Characteristics of Microservices Architecture

  1. Decoupled Components: Each service operates independently, with its own codebase and database.
  2. Independent Deployment: Services can be updated and deployed independently without affecting the entire system.
  3. Horizontal Scaling: Scaling can be achieved by adding more instances of specific services.
  4. Technology Diversity: Teams can use different technologies for different services based on their requirements.

Key Differences between Monolith and Microservices

  • Creation: A monolithic system is easier to build than one based in microservices architecture, thanks to it having a more basic overall design. Microservices architecture requires the use of a design that’s considerably more involved to plan and construct.
  • Debugging: Debugging works better in a more straightforward context, which is exactly what monolithic architectures offer.
  • Time to market: Time to market is metric that measures how quickly goods can be manufactured and put into distribution channels. Monolithic applications only use one codebase, which frees developers from having to incorporate software from multiple services.

How to select the best architecture - ERAS

Some questions to consider selecting the architecture:

  • How Important Are Performance and Scalability?
  • Where Will the Software Live?
  • How Rapidly Will the Application Evolve?
  • What Is the Skill Level of Your Development Team?

How to scale Monolithic architecture

Designing a monolithic architecture with future scalability in mind requires adopting patterns and principles that allow for modularity, maintainability, and a smooth transition to distributed systems if needed. Below are the key solutions for implementing a monolith architecture while considering future migration to microservices or event-driven architectures.

  • Modular Monolith: A modular monolith is a monolithic application divided into independent, well-defined modules that interact with each other through clear interfaces. Its key principles are: High Cohesion (Group related functionalities within a single module), Low Coupling (Minimize dependencies between modules). It facilitates extraction of individual modules into microservices in the future.
  • Layered Monolith: A layered monolith organizes the application into layers, each with a distinct responsibility, such as presentation, business logic, and data access. Its key principles are: Strict separation of concerns across layers and each layer interacts only with the layer directly below or above it.
  • Domain-Oriented Monolith: This approach uses principles from Domain-Driven Design (DDD) to organize the monolith into bounded contexts, each representing a distinct domain of the business. Its key principles are: Define clear boundaries for each domain, use domain models to encapsulate business rules and ensure that bounded contexts interact through well-defined APIs or domain events.

Common architecture styles used

When designing a monolithic system that is modular and scalable, architecture styles or design patterns play a critical role in defining the internal structure. These patterns provide guidelines for organizing the codebase and dependencies, ensuring the system is maintainable and adaptable for future growth.

Clean Architecture

Clean Architecture, proposed by Robert C. Martin, is a software design philosophy that emphasizes the separation of concerns into well-defined layers. This approach aims to create systems that are more maintainable, scalable, and testable.

Its key principles are:

  • Separation of Concerns: Different aspects of the application (e.g., business logic, user interface, data access) are separated into distinct layers.
  • Dependency Rule: High-level modules should not depend on low-level modules. Both should depend on abstractions.
  • Testability: The architecture should facilitate easy testing of the system by isolating components.
  • Flexibility: The system should be flexible enough to adapt to changes in requirements or technologies.

Clean Architecture

Onion Architecture

Onion Architecture is a software design approach that emphasizes the separation of concerns and the dependency inversion principle. It organizes the system into concentric layers, with the domain model at the core. Each layer depends on the one closer to the core but is unaware of outer layers.

Its key principles are:

  • Domain-Centric: The core of the architecture is the domain model, which contains the business logic and domain entities.
  • Dependency Inversion: Outer layers include application services, infrastructure, and UI, interacting with the core through interfaces.
  • Separation of Concerns: Different aspects of the application are separated into distinct layers, each with a specific responsibility.

Onion Architecture

Hexagonal Architecture

Hexagonal Architecture, also known as the "Ports and Adapters" architecture, is a design pattern that aims to create a flexible and maintainable system by decoupling the core business logic from external dependencies.

It organizes the application into a core logic surrounded by interfaces for communication with the outside world. These interfaces are categorized as "ports" (input/output operations) and "adapters" (implementations of these ports).

Its key principles are:

  • Decoupling: The core business logic is isolated from external systems like databases, user interfaces, and other services.
  • Ports and Adapters: The architecture defines "ports" as interfaces for communication and "adapters" as implementations of these interfaces.
  • Flexibility: The architecture allows for easy replacement or addition of external systems without affecting the core logic.

Hexagonal Architecture

Resources

Article: Monolithic Architecture Video: Choosing the correct architecture Article: Architecture Key Considerations Video: Monolith to Microservices Article: Clean Architecture Docs: Common Architectures with ASP.NET