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.
Top Online Courses 2021 (Offering Discount)
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.
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 .
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
Here I will explain you a simple step of building small microservice from scratch
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 )
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.
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
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.
Here are some of the key benefits why microservices becoming popular and has bright future for sustainable design.
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.