SSW Foursquare

Rules to Better Modular Monoliths - 2 Rules

A Modular Monolith is an architectural style in software development that emphasizes modularity within a monolithic application structure.

  1. Do you know the Modular Monolithic Architecture?

    A Modular Monolith is an architectural style in software development that emphasizes modularity within a monolithic application structure.

    Key aspects

    1. Monolithic Architecture - Traditionally, a monolithic application is a single-tiered software application where different components are combined into a single project. This means all components of the application are interconnected and interdependent
    2. Modularity - In a Modular Monolith, the application is still a monolith, but it's structured in a way that components or modules within it are highly modular. This modularity refers to dividing the application into distinct modules, each responsible for a specific piece of functionality. Eg. Invoicing These modules are designed to be loosely coupled, meaning they interact with each other through well-defined interfaces and are largely independent in terms of development and deployment
    3. *Use Cases - It's often used in scenarios where an application is expected to be complex but not so large or varied that it requires a distributed architecture. It's also a good fit for teams transitioning from a monolithic architecture to microservices, as it offers a middle ground

    ✅ Advantages

    • Simplicity in Deployment: Since it's a monolith, the deployment is typically simpler than distributed systems like microservices
    • Ease of Development: Developers can work on separate modules without significantly affecting other parts of the application
    • Performance: Inter-module communication is often faster and more reliable than inter-service communication in distributed architectures

    ❌ Challenges

    • Scalability: While more scalable than a traditional monolith, it may not scale as effectively as microservices
    • Modular Discipline: Maintaining strict modularity can be challenging as the application grows and evolves

    A Modular Monolith offers a balance between the simplicity and coherence of a monolith and the modularity and maintainability of more distributed architectures. It is particularly useful for certain kinds of applications and organizational contexts.

  2. Do you use MassTransit to build reliable distributed applications?

    When building distributed applications messaging is a common pattern to use. Often we might take a hard dependency on a specific messaging technology, such as Azure Service Bus or RabbitMQ. This can make it difficult to change messaging technologies in the future. Good architecture is about making decisions that make things easy to change in future. This is where MassTransit comes in.

    MassTransit is a popular open-source .NET library that makes it easy to build distributed applications using messaging without tying you to one specific messaging technology.

    .NET Messaging Libraries

    There are several .NET messaging libraries that all abstract the underlying transport. These include:

    There are also the service bus specific libraries:

    Advantages of using MassTransit

    ✅ Open-source and free to use

    ✅ Enables swapping of messaging transports by providing a common abstraction layer

    ✅ Supports multiple messaging concepts:

    • Point-to-Point
    • Publish/Subscribe
    • Request/Response

    ✅ Supports multiple messaging transports:

    • In-Memory
    • RabbitMQ
    • Azure Service Bus
    • Amazon SQS
    • ActiveMQ
    • Kafka
    • gRPC
    • SQL/DB

    ✅ Supports complex messaging patterns such as Sagas

    Scenarios

    Scenario 1 - Modular Monolith

    A Modular Monolith architecture requires all modules to be running in a single process. MassTransit can be used to facilitate in-memory communication between modules in the same process.

    This allows us to send events between modules and also request data from other modules.

    Scenario 2 - Azure Hosted Microservices

    When building microservices in Azure, it's common to use Azure Service Bus as the messaging transport. With minimal changes, MassTransit can be used to send messages to and from Azure Service Bus instead of using the In-Memory transport.

    Scenario 3 - Locally Developing Microservices

    When developing microservices locally, it's common to use containers for each service. However, some of the cloud based messaging services (e.g. Azure Service Bus) are not able to be run in a container locally. In this scenario, we can easily switch from using the Azure Service Bus transport to Containerized RabbitMQ transport

    Demo Code

    If you're interested in seeing MassTransit in action, check out github.com/danielmackay/dotnet-mass-transit

We open source. Powered by GitHub