Microservices Architecture: Benefits, Use Cases, and a Project Example

Microservices Architecture

Microservices or Microservices Architecture is an architectural pattern that consists of building a big system like a group of little systems that communicate between them.

Each service is designed to perform a specific function in the whole system and can be developed, deployed, and scaled independently. It’s crucial that each service has only one responsibility and does it well.

Within the system, microservices communicate using both synchronous and asynchronous methods. They might use REST, message queues (e.g., RabbitMQ), or gRPC, as demonstrated in this project.


Benefits of Microservices


When should you use Microservices?

Considering that this architecture is pretty difficult to implement, the decision has to be fair. It would be useful to consider using microservices when you fit with these points:

If the complete system is going to be developed by the same team, using the same database and in the same technology, it’s pretty likely that using microservices architecture will be over-engineering.



Project Overview

In this repository there’s a pretty simple project built with the goal of learning microservices architecture, following this fantastic course: .NET Microservices Course

The project consists of two very simple services:

Also, there is a HTTP message that is sent to the Command Service when a platform is created, just with the goal of testing that approach.

It’s very important to consider that if both services don’t share data between them, then they’re not theoretically part of a microservice architecture.

The solution architecture is here:

diagram

In the diagram, we can see:



Running the project

It was developed using .NET 8.0. The project can be ejected locally in a Kubernetes cluster as a production environment. In order to do that, you have to follow the instructions below:

Prerequisites: Ensure you have kubectl installed. Follow the instructions for your operating system:

  1. Clone the repository
    git clone https://github.com/PabloMusaber/microservices-architecture.git
    
  2. Create a Kubernetes Secret for SQL Server
    kubectl create secret generic mssql --from-literal=SA_PASSWORD="pa55w0rd!"
    
  3. Apply Kubernetes Configurations:
    kubectl apply -f K8S/local-pvc.yaml
    kubectl apply -f K8S/mssql-plat-depl.yaml
    kubectl apply -f K8S/rabbitmq-depl.yaml
    kubectl apply -f K8S/platforms-depl.yaml
    kubectl apply -f K8S/platforms-np-srv.yaml
    kubectl apply -f K8S/commands-depl.yaml
    kubectl apply -f K8S/ingress-srv.yaml
    
  4. Deploy Ingress-NGINX for API Gateway
    kubectl apply -f https://raw.githubusercontent.com/kubernetes/ingress-nginx/controller-v1.12.0-beta.0/deploy/static/provider/cloud/deploy.yaml
    
  5. Configure Hosts File: Add 127.0.0.1 acme.com to your hosts file (Windows: C:\Windows\System32\drivers\etc\hosts, Linux: /etc/hosts) for the API Gateway.

  6. Test with APi client: Use the Test_Microservices_Course_Collection.json postman collection in your API client. You might need to disable SSL/TLS certificate validation.