Microservices in .NET Core

Share

Not so long ago, a software development project for a large global chain of furniture stores appeared in our company. It was up to us to choose the technologies and architecture that would be used in the Backend. After a detailed reading of the documentation, experiences of other developers, and tutorials on the Internet, we finally decided to develop the software in the microservice architecture on the .NET Core 2.0 platform. The application was hosted on Amazon Web Services using Docker containers. The team that worked on the Backend was delighted with the choice of architectural solution and modern technologies, so we’ve decided to describe and explain in this blog the advantages that modern technologies have over the traditional solutions.

Microservice architecture

The fact that digitalization has taken off during the last decade and that the business demands have become greater leads to the development of complex software solutions that require a lot of time for development and delivery. With the traditional monolithic architecture, every time a QA team reports a problem with an application it needs to be debugged, the problem segment has to be corrected, and then the entire code gets re-published to the server. If there are multiple clients in the system using the application (web client, mobile client, etc), the work on all clients will be suspended until the problem is resolved, and the system performance declines. Another problem with such an architecture is that it’s difficult to divide the projects into segments which would enable the team members to develop more or less independently of each other. In order to reduce the complexity of large systems, many organizations are turning to the microservice architecture. Among the first once to do so were giants like Amazon and Netflix, as well as companies with a huge user base such as SoundCloud.

The microservice architecture represents the evolution of the service-oriented architecture (SOA) and is made up of a set of independent services, each of which implements one business requirement. The basic characteristics of the microservice architecture are:

  • All of the services are small, simple and mutually independent;
  • Each service is a separate project that can be implemented and maintained by a small development team; 
  • Each service can be published to the server independently from the rest, and this enables a team to alter an existing service with no consequences for the rest of the system;
  • Each service has its own database model;
  • The services communicate with each other using the predefined APIs, and the internal implementation of each service is hidden from the other services;
  • The services don’t have to be developed in the same technologies.

Some of the advantages of using the microservice architecture over the traditional monolithic architecture are: independent publishing of services to the production servers without any consequences for the rest of the system, greater scalability, independent development in small teams focused on one business requirement per team, etc. Due to all this, the use of microservice architecture is recommended for the implementation of complex and extensive software solutions.

Tnimg1Image 1: Comparison of the monolithic (to the left) and the microservice architectural approach (to the right)

.NET Core

As mentioned earlier, we developed WebAPIs in the Backend on the .NET Core 2.0 platform. Given that this is a very recent technology (version 2.0 was released in August 2017 and version 1.0 in May 2016), the big challenge was not to run into various obstacles during development, which would be very difficult or impossible to overcome. However, the internet programming community had from the very start noticed a huge advantage of cross-platform technology, so for every problem we encountered, there were described or suggested solutions on the Internet.

The .NET Core is an open source implementation of the .NET APIs that are formally specified in the .NET Standard and that can run on different platforms (cross-platform). It contains a lot of the same APIs as the .NET Framework itself, but the set of APIs in the .NET Core is smaller. The main features of the .NET Core are:

  • Cross-platform – one of the most important features, it allows the code to be implemented and run in different operating systems. It currently supports three major operating systems: Windows, Linux, and macOS;
  • Open source – the implementation of the .NET Core is available on GitHub, thus promoting the transparent process of development;
  • The flexible publishing of applications to the server – environment-dependent publishing and independent publishing. The first method means that, when publishing to the server, only the application and its packages will be installed, and the application depends on the version of the .NET Core installed on the system. The second method assumes that, when publishing an application to the server, the version of the .NET Core used for development will be installed together with the application and all its packages and that version will run independently of other versions of the .NET Core installed on the system;
  • Modularity – means that it’s divided into smaller packages available through the NuGet package manager.

Microservices on the .NET Core platform in combination with Docker

Docker is a tool designed to facilitate the development, publishing to the server and running the application using containers. There are Windows and Linux containers. The containers allow the developer to place together the application and all the packages on which it depends, so that they can be treated as one package. This way, the developers can be sure that the application will run on any machine (Windows containers on Windows OS and Linux containers on other OS), regardless of the specifics of the machine itself. In a way, Docker is like a virtual machine, but unlike a virtual machine that creates the entire operating system, Docker allows the application to use the same kernel as the system on which it runs and only requires the application to come with the packages that aren’t installed on the host computer. This significantly reduces the size of the application.

The containers are usually used in combination with the microservice architecture, although they can also be used for applications and services that follow other architectural schemes. The .NET Framework can be used on Windows containers, but the modularity and simplicity of the .NET Core makes that platform very suitable for the containers and the microservice architecture.

A microservice should be very simple to execute; it should implement a small segment of the business process; and it should be able to process the requests quickly and respond back. To meet all of these requirements, it’s best to use the .NET Core platform in combination with Docker. We had a great experience with this combination of architectural solution and choice of technology.

Img001Image 2: Docker containers with the packages

Amazon Web Services (AWS)

In the end, the application was to be published on the Amazon Web Services (AWS).

The AWS is a secure cloud platform that offers application hosting services, provides storage space and many other services. The AWS had a tool (AWS Toolkit) for Visual Studio 2017, which allowed us to easily develop a dockerized microservice and publish to the AWS through the Visual Studio itself using the ECS (Elastic Container Service). Since, according to the project documentation, the data model was non-relational, we used Amazon’s NoSql database DynamoDB as a database, which is easy to work with using the SDK for the .NET Core. Another thing that made us opt for DynamoDB is that all the microservices that depend on data from a particular microservice can read any changes directly from the DynamoDB stream.

This project was really great because it included a lot of new and modern technologies and solutions. The Backend team was happy and inspired to develop because they were keeping up with the times and learning the latest stuff about the Microsoft technologies. We believe that in future there will be many more such projects, through which we will be able to learn and follow modern technologies and methodologies.

Share

Sign in to get new blogs and news first:

Leave a Reply

Slaviša Božović

Senior Software Developer @ TNation
mm

The Senior Software Developer with many years of experience developing software on .NET platform for the financial institutions in Serbia. He’s highly motivated to learn new technologies and apply new methodologies in programming. Slaviša’s interested in the .NET platform, microservice architecture, algorithmics, etc. He believes that to every problem to which there’s a complex solution, there must also be a less complex solution, so he’s always searching for it. Privately, he’s a “party maniac” and loves to travel.

Sign in to get new blogs and news first.

Categories