Microservices in .Net Core

What is microservice? How to design microservice using .net framework! Asp.net Core Microservices tutorial in C# for beginners

Microsoft has introduced a service oriented architecture that can be containerized and independent. Microservices are type of API service, that are small, modular, can be deployed independently, which can run in an isolated environment.

What is Microservices in .Net Core?

You also can say Microservices is a type of SOA (Service Oriented Architecture), an architectural design that separates portions of an application into small, self-containing services, one Microservice can have multiple services within it, but it’s designed as small as necessary.

There is fantastic document for .NET Microservices Architecture Guidance from Microsoft.

Microservices Characteristic

  • Any microservice is self independent, deployment and consumption will not depend on anything, so if you have multiple micro services as a part of any big enterprise system, there are chances that you may have same data duplicated in different micro service, as per micro service design principal that’s not incorrect design.
  • So while designing any microservices we should try to minimize the interaction between the internal microservices, the less interaction between microservices is better, but in some situation you may need to integrate other microservices as per business demand, in such cases make sure all communication are asynchronous.

Microservices Architecture

As explained earlier micro services are small independent service that can interact with any number of services or different type of clients, but to understand it in typical enterprise scenario where probably we can have any number of micro services and any number of applications, following picture is the representation of one such scenario .

microservices architecture

Difference between Web API and Microservices

At this point you may think what’s the difference between Web API and Microservices, because there are many similarities.

The main conceptual difference is, Microservices is an architectural pattern of building small independent services that can work with multiple systems, so from business point of view, you can build multiple Microservices rather than building a big system together.

When API is designed for providing a cross platform data interoperability mechanism, where Microservices is much bigger picture.

Now if you think of a big enterprise business, where business demand is constantly changing, and there are so many interdependency factors, so maintaining everything in one system become tough, impact analysis takes lots of time, also there are high risk involved. And that’s where Microservices makes the job much easier and easy to maintain, that’s the reason Microservices architecture is becoming so popular

How to build Microservices

Here I will explain you a simple step of building small microservice from scratch

microservices architecture

Select .Net Core framework and “API ” project, if your operating system supports docker then you can enable docker otherwise ignore , (if you are developing on windows 10 then probably you have docker support, if using windows 7, then please ignore )

microservices architecture

If you are using Visual studio 2019, then you may see the following screen

Note: to understand microservice you can uncheck the SSL and Docker checkbox to avoid unncessary configuration realted task, you can add those configuration later.

microservices architecture

As you can see at the picture below, how the same microservice project will look like with and without docker setting.

But in tutorial we will focus more microservice desining tips and best practices, and avoid the docker part, at next article we will look at how to setup docker configuration in asp.net microservices

microservices architecture

launchsettings json in microservice

launchSettings.json file contain setting information about how the project will run in local environment, remember this file is not required when we finally publish the application, but just for you knowledge, you can run your application differently in local environment, either by using kestrel web server (which is application name) or by using the IIS Express.

launchsettings json in microservice

Microservices Benefits

Here are some of the key benefits why microservices becoming popular and has bright future for sustainable design.

  • Each microservice is loosely coupled
  • Independently deployable, means we need not to worry about impact of other services
  • Small business function maintained by small team
  • Easily maintainable and testable

In my next article, I will publish a real-time microservice solution with full source code and implement complete microservice architecture with few design pattern like CQRS (Command Query Responsibility Segregation), DDD (Domain Driven Design), Database per Service, so you will get everything ready to use for learning as well as using for your own development.

Asp.Net Core C# Examples | Join Asp.Net MVC Course