25. Microservices, Monolith Structure (I)

Microservices and Monolith Structure

Introduction

Microservices and Monolith are architectural styles for designing and developing software applications. They are key concepts in the field of software engineering, each with its unique advantages and challenges.

Monolith Architecture

A Monolith Architecture is a traditional unified model for the design of a software application. It's a single-tiered software application in which the user interface and data access code are combined into a single program from a single platform.

Purpose

The primary purpose of a monolith architecture is to separate the business layer from the logic view. This separation allows for more straightforward design and development processes and easier maintenance.

Microservices Architecture

A Microservices Architecture, on the other hand, is an architectural style that structures an application as a collection of small autonomous services, modelled around a business domain.

Advantage

One of the significant advantages of a microservices architecture is its resilience. If there is a problem with one of the services, it does not cause the entire project to crash. Only the problematic service is affected, minimizing the risk and impact of service failure.

For example, consider a project with various applications such as WPF, web, mobile app, etc. These applications can communicate with the microservices via an API gateway. Here, the gateway knows which service to connect to.

# An example of a microservice connection through an API gateway
api_gateway.connect('microservice_1')
api_gateway.connect('microservice_2')

Messaging Broker

A Messaging Broker is a tool that helps to translate messages between different application languages. It is an intermediary program module that translates a message from the formal messaging protocol of the sender to the formal messaging protocol of the receiver.

Ocelot.json

ocelot.json is a file used to explain what requests the API gateway will execute. It is an essential part of the API gateway configuration, specifying the routing, load balancing, and other parameters.

// An example of ocelot.json
{
  "ReRoutes": [
    {
      "DownstreamPathTemplate": "/api/values",
      "DownstreamScheme": "http",
      "DownstreamHostAndPorts": [
        {
          "Host": "localhost",
          "Port": 6000
        }
      ],
      "UpstreamPathTemplate": "/api/values",
      "UpstreamHttpMethod": [ "Get" ]
    }
  ],
  "GlobalConfiguration": {
    "BaseUrl": "<http://localhost:5000>"
  }
}

In this JSON example, the API gateway will route the request to the /api/values endpoint of the service running on localhost:6000. The gateway itself is running on http://localhost:5000.

Conclusion

Understanding the concepts of Microservices and Monolith structures, as well as how they are implemented through tools and configuration files like ocelot.json, is crucial in modern software development. It empowers developers to build scalable, resilient, and maintainable software systems.

Reference

The content in this document is based on the original notes provided in Azerbaijani. For further details, you can refer to the original document using the following link:

Original Note - Azerbaijani Version