Поиск  
Always will be ready notify the world about expectations as easy as possible: job change page
Nov 7, 2020

Using Microservices in .NET Core and Docker container

Автор:
Rebai Hamida
Источник:
Просмотров:
3190

Introduction

During this article, we will learn how to work with the microservice architecture patterns and Docker containers using the .NET Core 3 platform to build a distributed system.

Monolithic vs Microservices Architecture

Before talking about Microservices, we need to understand the difference between traditional application approach and microservices application approach.


https://martinfowler.com/articles/microservices.html

Any application is built as a collection of services can be developed, tested, versioned, deployed, and scaled.

For Monolithic applications, Scales is done by cloning the app on multiple servers — VMs.

But for microservices, scales is done by deploying each independently with multiple instances across servers — VMs.


Monolithic vs Microservices Architecture

When developing a server-side application you can start it with a modular hexagonal or layered architecture which consists of different types of components or layers:

  • Presentation Layer — UI layer, this can be a web or mobile or desktop application.
     
  • Services Layer — responsible for handling HTTP requests and responding with either HTML or JSON/XML (for web services APIs).
     
  • Business logic Layer — the application’s business logic.
     
  • Database access Layer — data access objects responsible for access the database.

Despite having a logically modular architecture, the application is packaged and deployed as a monolith.

Monolithic applications are more of a single complete package, having all the related needed components and services encapsulated in one package.

But for microservices, the idea is simple, it consists to split your application into a set of smaller, interconnected services instead of building a single monolithic application. Each microservice is a small application that has its own hexagonal architecture consisting of business logic along with various adapters. Some microservices would expose a REST, RPC or message-based API and most services consume APIs provided by other services. Other microservices might implement a web UI.

Microservices are deployed independently with their own database per service so the underlying.

Microservices architecture and Patterns

One thing about microservices is there are different things that you can use, those technologies for microservices or not but if we choose building and architecting an Microservices there are many patterns most of them are related or coming from domain driven design. I will talk about some of them after.


Microservices architecture stylePatters and technologies

Microservices architecture style


Microservices architecture style

Developers consider Microservices as architectural style that promotes the development of complex applications as a suite of small services based on business capabilities and multiple, independent subsystems in the form of autonomous services.

The following picture shows the microservices architecture style.

There are various components in a microservices architecture apart from the microservices themselves.

We start from a client that interact with a server using an authentication using Identity Provider that manages the identity information and provides authentication services within a distributed network. To ensure this interaction, we need a client’s entry point that is API Gateway. It’s a single point of contact from the client which, in turn, returns responses from underlying microservices and sometimes an aggregated response from multiple microservices, in our schema, we have four services that use the Management that maintains the nodes for the service. And to keep the track of services and service addresses and endpoints, we use Service Discovery.

We have CDN that it a content delivery network to serve static resources. For example, pages and web content in a distributed network and the Static Content is a static resources like pages and web content.

We will talk more in detail about API Gateway:


API Gateway

An API gateway is located between the clients and the services. It acts as a reverse proxy, routing client requests to services. It can also perform various cross-functional tasks such as authentication, SSL termination, and rate limiting. If you do not deploy a gateway, clients must send requests directly to the front-end services.
This creates a coupling between the client and the server. The customer must know how each service has been broken down. these make customer maintenance more difficult and refactoring services.

Now, we need to deploy our services in container, to do that, we will use Docker.

Docker container


Docker and Azure

Docker is a tool that facilitates the creation, deployment, and execution of applications using a containerization approach.

These containers are lightweight and take less time to boot than traditional servers. These containers also increase performance and reduce costs, while providing appropriate management of resources. Another advantage of Docker is that it is no longer necessary to pre-allocate RAM to each container.

Microservice using ASP.NET Core

And before we start modeling our microservices architecture using the strategies and techniques in this course, we need a problem to solve, and this is where this case study comes in. And our case study is based around booking medical appointments.

Prerequisites Environment

  • Visual Studio 2019 or 2017 has built-in support for Docker
  • Windows 10 is required for Docker installation.
  • .NET Core SDK
  • Docker for Windows
  • Docker Tools

Creating an Asp.NET Core 3 Application Solution

I started from this old solution, N- Layered application and it include Web APIs. And we need to change that for Microservices.

GitHub: https://github.com/didourebai/Plateforme.AlloTabib-Before


N-Layered Monolithic architecture

This application has this structure:

  • Service Layer: include all APIs used and integrate swagger framework.


    Web APIs and Swagger


    User Account API

  • Application and Domain layer: this is the business layer.
  • Two web applications: using MVC 4 and AngularJS.
  • Infrastructure layer is the Database access layer.

We create a new blank solution to include all API project that are our services:


Visual Studio 2019


API with Docker enabled

Or if we can use Docker with an orchestrator Kubernetes, it is ready Core Web application:


Docker and Kubernetes



API

Push Docker images to Azure Container Registry

HTTP Client Factory

To ensure a resilient cloud application, we need to implement resilient communication with retires.

To implement that, we use the best library for retries and sql breaker is Poly, an open source. So, you can handle or you can implement HttpClient in your application with Http Factory in .net Core.

Orchestrators in Azure

We can use Kubernetes with Docker or Service Fabric if our microservices is based on plain processes and it is more used for stateful services.


Orchestrators in Azure

Conclusion

This article was an overview about Microservices with Docker, microservices allow to evolve deploy and scale parts of the application independently but we can’t use this architecture for small application because it is dedicated to distributed software challenges and for scalable and long term evolving applications.

Похожее
Feb 12
Author: Kartik
Application Insights - Telemetry 1. How do I instrument (monitor/record/enabling to capture telemetry) an application? Autoinstrumentation - if you don’t have access to source code You only need to install the Application Insights SDK if: You require custom events and...
17 декабря 2014 г.
Краткий обзор .NET Core, как это соотносится с .NET Framework и что это все означает для кросс-платформенной разработки и разработки с открытым кодом. Взгляд назад – мотивация для .NET Core Прежде всего, давайте оглянемся назад, чтобы понять, как платформа .NET...
Jan 21, 2021
The primary purpose of any caching mechanism is to improve performance of an application. As an ASP.NET developer you are probably aware that ASP.NET web forms as well as ASP.NET MVC could used Cache object to cache application data. This...
Sep 14, 2023
Author: Rico Fritzsche
Balancing Business Needs: Evaluating Architecture in Domain-Driven Design One topic has come up again and again over the years, sometimes more, sometimes less, in conversations among developers: What’s the best way to modularize software? As a longtime software developer, I’ve...
Написать сообщение
Тип
Почта
Имя
*Сообщение