📜 ⬆️ ⬇️

Reference application based on containers and microservice architecture

Habr, hello. Today we are telling you about Microsoft's reference .NET Core cross-platform application, created on the basis of Docker’s simplified microservice architecture and containers. The article will share a large amount of technical data, documentation, books on the topic, as well as useful links. And, of course, video, for better understanding. Join now!



news
Do you want to be among the first to get current recommendations on .NET architecture and reference applications like eShopOnContainers? -> Click Follow in this new GitHub repository.

Note Required version of Visual Studio 2017: VS 2017 15.5 and higher.
')

Updates for the "wave" technologies. NET Core 2.0 Wave


Note
We completely migrated to the .NET Core 2.0 Wave server-side solution: not only a compilation, but also a new recommended code in EF Core 2.0, ASP.NET Core 2.0 and other related new versions.

The dockerfile files in the solution were also updated, they support Docker Multi-Stage from mid-December 2017.

A list of implemented features related to .NET Core 2.0 is provided in this publication .

Do not forget to read our branch guidelines covering the principles of the relevant policy.

Denial of responsibility
This is a beta version of the sample application, as we are constantly improving technologies and preparing new releases of solutions based on them. We can significantly improve and modify many functions during the refactoring of the current code and the implementation of new features. We look forward to the improvement proposals and requests from the community.

In this reference application, a microservice oriented architecture is implemented in a simplified form. It is designed to use technologies such as .NET Core with Docker containers as part of a universal application. We chose the direction of "electronic stores / e-commerce" simply because most users and developers are familiar with it. However, this sample application should not be viewed as a “reference model for e-commerce”. This implementation is not at all optimal from the point of view of trading via the Internet. We are not trying to solve all problems within a large, scalable, and critical distributed system. The main goal is to help developers quickly and effortlessly get started with Docker containers, microservices and the .NET Core platform.

For example, after a developer launches a solution on a local computer and becomes familiar with the principles of using Docker containers and microservices in .NET Core, he will need to choose a microservice cluster / orchestrator like Kubernetes in Azure or Azure Service Fabric (both environments were tested and supported by this solution). ). Additionally, you may need to transfer databases to highly available cloud services (for example, an Azure SQL database) or implement your EventBus event bus using an Azure service bus or any other available on the market.



Check out the plan and key milestones for future eShopOnContainers releases on wiki pages. Here you will learn about the planned releases and will be able to leave a review in the ISSUES section (QUESTIONS) if you need to implement or improve a specific scenario. In addition, you can participate in the discussion of any of the previously asked questions.

Architecture Overview


This reference application is cross-platform both on the server side and on the client side by launching .NET Core services in Linux or Windows containers (depending on the Docker host you are using), as well as using Xamarin for mobile applications running on Android platforms , iOS or Windows / UWP (in the latter case, any browser is suitable for launching client web applications). It implements a simplified version of the architecture with several autonomous microservices, each of which has its own data and database and uses its own approach (simple CRUD templates, DDD / CQRS templates).

HTTP serves as a communication protocol between client applications and microservices. In addition, asynchronous communication is supported for transferring updated data to several services based on integration events and an event bus (a lightning message-based broker based on RabbitMQ or an Azure service bus) and other functions defined in the product development plan .




Important notice about API gateways and published APIs
Notice that the architecture diagram above shows how eShopOnContainers is deployed on the local Docker developer machine. For an architecture that is ready for deployment in a production environment, we recommend that you continue to extend your architecture with additional features, such as API gateways based on the Azure API Management Service or any other approach to working with the API gateways described in the corresponding documentation / e-book. This will allow filtering API and used security tools at the same level, as well as hide / protect internal microservices from client applications and external users.



The sample code in this repository does NOT use the Azure API Management service to provide “F5 use” in Visual Studio (or CLI) for a sample that does not have previously created dependencies in Azure. However, you should choose a suitable approach to working with API gateways when preparing a solution for deployment in a production environment.

Microservices differ in type, that is, the implementation of the internal architecture can be implemented differently depending on its purpose, as shown in the figure below.



Regarding the current configuration of this solution for the development environment, SQL databases with sample data are automatically deployed into one SQL Server for Linux container (one common Docker container for SQL databases), so the entire solution can be run independently of the cloud or a specific server. Each database can also be deployed as a separate Docker container, but then you need more than 8 GB of RAM for Docker on the developer’s machine to run three Docker containers for SQL Server on the used Docker Linux node in the Docker for Windows or Docker development environment for Mac.

The same applies to the Redis cache, launched as a container for the development environment, as well as the NoSQL database (MongoDB) running in container mode.

However, in a real production environment, it is recommended to deploy databases (in our case, SQL Server, Redis and NoSQL) in high availability services such as Azure SQL database, Redis as a service and Azure CosmosDB, rather than in the MongoDB container (since both systems use same access protocol). When switching to a production configuration, you just need to change the connection strings after setting up the servers in a highly available cloud or locally.

Related documentation and recommendations


During the development of this reference application, we are preparing a reference guide / e-book on architecture design and .NET-based application development based on containers and microservices (see download link below). It describes in detail the approaches to the application of this architectural style (microservices, Docker containers, object-oriented design for certain microservices), as well as other simplified architectural styles, including monolithic applications, which can also be deployed as Docker containers.

You can also get acquainted with other electronic publications dedicated to the life cycle of containers / Docker (DevOps, CI / CD, etc.) and Microsoft tools, as well as with an electronic book about enterprise application templates based on Xamarin.Forms. Download and read reference guides / e-books:
Architecture Design and DevelopmentContainer and CI / CD life cycleApplication Templates Based on Xamarin.Forms
Download PDF (second edition)DownloadDownload
These books in other formats (for example, MOBI and EPUB) and other electronic publications are available in the .NET architecture center .

Feedback address: dotnet-architecture-ebooks-feedback@service.microsoft.com

We recommend downloading and reading the e-book “Architectural Design and Development of Microservices ” ( Architecting and Developing Microservices ). When describing architectural styles, patterns and technologies, the authors refer to this reference application to explain the approaches to the implementation of many patterns, so you will better understand the context, design and decisions made in the current architecture and interior projects.

Application Code Overview


This repository stores a sample reference application that helps you understand how to create an application based on microservice architecture using .NET Core and Docker .

An example of a business direction or scenario - an online store or an e-commerce service - is implemented using a multi-container application. Each container is a deployed microservice (for example, a basket microservice, a catalog microservice, an order checkout microservice and an identification microservice), which is developed using ASP.NET Core based on .NET Core and therefore can be run in Linux or Windows container services. The screenshot below shows the structure of the VS solution for these microservices / containers and client applications.




Finally, these microservices are used by several client web applications and mobile applications, as described below.

MVC application (ASP.NET Core) : contains interesting usage scenarios for HTTP-based microservices from C # that work on the server side, since this is a typical ASP.NET Core MVC application. It works on the server side, so access to other containers / microservices is done on the internal network of the Docker node with its internal name resolution.



SPA (Single Page Application - one-page application) : the same “online store functionality”, but developed on the basis of Angular, Typescript and some ASP.NET Core MVC. This is another approach to developing client web applications that allow for more modern client behavior, more like a one-page desktop application than a typical browser solution. Clients access HTTP-based microservices via TypeScript / JavaScript in the client browser, so calls to microservices do not come from the internal network of the Docker host, but, for example, from your network or even from the Internet.



Xamarin mobile application (for iOS, Android and Windows / UWP) : this client mobile application supports the most common mobile OS (iOS, Android and Windows / UWP). In this case, C # is used to access microservices, but on client devices: requests come not from the internal network of the Docker host, but, for example, from your network or even from the Internet.



Setting up the development environment for eShopOnContainers


For Visual Studio 2017 and Windows


From this it is advisable to start.

For CLI and Windows


For those who prefer CLI on Windows, dotnet CLI, docker CLI and VS Code for Windows: tyk .

For CLI and Mac


For those who prefer CLI on Mac, dotnet CLI, docker CLI and VS Code for Mac: tyk .

Orchestrator: Kubernetes and Service Fabric


Check out the configuration wiki posts, which are recommendations for deploying to Kubernetes and Service Fabric in Azure (however, you can use them in any other cloud or locally).

By the way, here you can read our recent article about containers in Azure.

Source: https://habr.com/ru/post/346746/


All Articles