Advertisement
Поиск  
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
Источник:
Просмотров:
1362

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.

Похожее
Mar 16
Author: Winds Of Change
Performance is paramount when developing web applications. A slow, unresponsive application results in poor user experience, losing users, and possibly business. For ASP.NET Core developers, there are many techniques and best practices to optimize application performance. Let’s explore some of...
Mar 9, 2023
Author: Vithal Wadje
ASP.NET Core Blazor Server is a platform for developing modern and dynamic web applications. With Blazor Server, you can write code in C# and create rich user interfaces using HTML and CSS, all while taking advantage of server-side rendering and...
Jan 29
Author: Alex Maher
Performance tricks & best practices, beginner friendlyHey there! Today, I’m sharing some straightforward ways to speed up your .NET Core apps. No fancy words, just simple stuff that works.Let’s dive in!• • •1. Asynchronous programmingAsynchronous programming in .NET Core is...
May 2, 2023
Microservice architecture is one of the most discussed software architecture trends at the moment, and it has forever changed the way enterprise applications are built. Rather than the slow, complex monolithic approach of the past, developers and companies everywhere are...
Написать сообщение
Почта
Имя
*Сообщение


© 1999–2024 WebDynamics
1980–... Sergey Drozdov
Area of interests: .NET Framework | .NET Core | C# | ASP.NET | Windows Forms | WPF | HTML5 | CSS3 | jQuery | AJAX | Angular | React | MS SQL Server | Transact-SQL | ADO.NET | Entity Framework | IIS | OOP | OOA | OOD | WCF | WPF | MSMQ | MVC | MVP | MVVM | Design Patterns | Enterprise Architecture | Scrum | Kanban