• Level Up Coding
  • Posts
  • LUC #33: Breaking Down Modular Monolithic Architecture: Blending Tradition with Innovation

LUC #33: Breaking Down Modular Monolithic Architecture: Blending Tradition with Innovation

Plus, Strategies to optimize CI/CD pipeline performance, how CORS works, and what makes an API RESTful?

This week’s issue brings you:

READ TIME: 6 MINUTES

A big thank you to our partner Postman who keeps this newsletter free to the reader.

You can now simulate real-world traffic on your local machine to performance test your APIs. With debugging info readily available too. A very useful release from Postman earlier this year. And it's available on their free tier. Check it out.

Breaking Down Modular Monolithic Architecture: Blending Tradition with Innovation

Modular Monoliths are becoming increasingly popular in the software engineering community, offering a balance between the simplicity of traditional Monoliths and the flexibility of Microservices.

This architectural style elegantly addresses complex software challenges that arise in Monolithic and Microservices architecture, providing engineers with a streamlined approach to building software and maintenance.

By blending the best of both worlds, Modular Monoliths emerge as a compelling choice in today's diverse and demanding engineering environment. Now, let's delve deeper into what exactly a Modular Monolith is and how it differentiates from its counterparts.

Understanding Modular Monoliths

Modular Monoliths represent a unique blend in software architecture – they are monolithic systems yet designed with an emphasis on modularity.

This allows each component, or module, to be developed independently but function cohesively within a single, unified system.

The essence of a modular monolith is captured in its:

  • Internal modularity: the system comprises many loosely coupled independent modules, each offering a cohesive set of functionalities within the larger system.

  • Single deployable unit: despite modularization, it remains a single entity for deployment, mitigating the distributed operational complexity that comes with Microservices.

  • Shared database(s): modules typically interact with the same database(s), which simplifies data management and data integrity compared to the distributed database approach in Microservices.

Modular monoliths strike a middle ground combining the straightforwardness of traditional Monoliths with the modular flexibility of Microservices, but without the operational complexity.

Advantages of Modular Monoliths

Simplified Complexity

Modular Monoliths offer a straightforward architecture, making development and maintenance simpler than the often complex Microservices approach. This simplicity is achieved through a unified codebase, which eliminates the intricacies of managing a distributed system. The result is a streamlined development process, allowing teams to focus on solving business problems rather than navigating operational complexities.

Improved Performance

In Modular Monoliths, the single-process architecture facilitates rapid communication between modules. This setup outpaces the slower network calls found in microservices, leading to significantly enhanced performance. Especially in scenarios demanding quick inter-module interaction, this efficiency is a key advantage, providing a smooth and responsive system.

Enhanced Data Consistency

The centralized data management approach in Modular Monoliths simplifies transaction handling, offering a stark contrast to the dispersed data management in Microservices. This centralization ensures robust data integrity and consistency across the application, making it easier to maintain and safeguard the system's data quality and reliability.

Building a Modular Monolith

Building a modular monolith requires a careful balance of design principles and implementation strategies to ensure the system's efficiency and maintainability.

Central to this approach are loose coupling and high cohesion among modules, allowing each to operate independently within the larger system. Here are some examples:

  • Product Catalog Module: Manages product listings and information.

  • Payments Module: Handles all aspects of payment processing.

  • Shipping Module: Oversees shipping logistics and tracking.

  • Reviews Module: Manages customer reviews and feedback.

Designing these modules to be self-contained means that changes in one module have minimal impact on others, thus enhancing the system's stability and flexibility.

A crucial aspect of Modular Monoliths is establishing defined interfaces for communication between modules. These interfaces act as contracts, ensuring that modules interact consistently and predictably, simplifying interactions while maintaining module independence, a vital attribute for scalable and robust architecture.

In implementing a Modular Monolith, it's essential to focus on these clear boundaries and interfaces between modules. The goal is to create an architecture where changes in one module do not necessitate alterations in others.

Keeping an eye on future scalability and potential transitions to a Microservices architecture from the outset can also guide the initial design choices, ensuring that such transitions, if required, are smoother and more manageable.

Challenges and Considerations

While Modular Monoliths offer numerous benefits, they also present potential pitfalls that require careful consideration:

  • Risk of Tight Coupling: If not designed with strict adherence to modularity principles, there's a risk of creating tight coupling between modules, which can negate the benefits of this architecture.

  • Scaling Challenges: Compared to Microservices, scaling a modular monolith can be more complex, especially in terms of handling large volumes of transactions or data.

To mitigate these challenges, certain best practices should be followed:

  • Maintaining Modularity: Regular refactoring is crucial to prevent codebase bloat and ensure each module remains independent and focused.

  • Strategies for Scaling: Planning for scalability from the outset is essential. This includes considering how the system might transition into Microservices in the future if required.

The Rise of Modular Monoliths

The popularity of Modular Monoliths continues to rise. The combination of simplicity with modularity, scalable design, straightforward refactoring, as well as the ability to easily migrate to Microservices are attractive attributes.

Martin Fowler aptly states, “You shouldn't start a new project with microservices, even if you're sure your application will be big enough to make it worthwhile.” This perspective underscores the importance of considering Modular Monoliths, especially for projects where their distinct advantages align with the project's goals and complexities.

Strategies to Optimize CI/CD Pipeline Performance (Recap)

  • Start with identifying the bottlenecks and inefficiencies.

  • Identify processes that run in sequence and consider if they could instead run in parallel.

  • If possible, only run tests that relate to the set of changes.

  • Optimize your build process — check the efficiency of your build scripts, remove unnecessary dependencies, cache artifacts, and avoid unnecessary processes.

  • Ensure the infrastructure can support your pipeline to scale as needed.

How Does CORS work? (Recap)

Web browsers use Cross-Origin Resource Sharing (CORS) to manage requests made to a different domain than the one serving the web page. It's a security mechanism to mitigate the risks of cross-site attacks. Below is a simple breakdown of the workflow:

  1. For non-simple requests, the browser first sends a preflight request.

  2. The server responds to the preflight request with the appropriate CORS headers.

  3. The browser then sends the actual request with any necessary credentials, data, or headers.

  4. The server processes the request and sends back the response with the appropriate CORS headers.

What Makes an API RESTful?

Representational State Transfer (REST) is an architectural style that is commonly used for web-based APIs alongside HTTP as the transport protocol.

Key concepts:

  • Stateless: The server shouldn’t need to store any information about a user between requests. Everything that the server needs to execute a task should be sent in the request.

  • Separation of concerns: The client and server should function independently of each other.

  • Cacheable: Responses can be cached on the client to boost performance.

  • Consistent interface: By using HTTP methods like GET, POST, and DELETE, API interfaces stay consistent.

  • Resource-based: RESTful APIs have an emphasis on resources rather than methods or functions. A resource can be an object, entity, or data within a system. Resources are uniquely identified using a Uniform Resource Identifier (URI).

  • Standard media types: Responses are usually sent as JSON, XML, or plain text. Clients can request a preferred media type.

That wraps up this week’s issue of Level Up Coding’s newsletter!

Join us again next week where we’ll explore containerization, stateful vs stateless design, HTTP status codes, and how the DNS lookup process works.