What are Microservices? Historically applications were Monolithic applications where the architecture was a unified and closely coupled integrated unit. Microservices, on the contrary, are smaller independent unified business modules. Each module in Microservices performs its own unique business functionality, at times with dedicated databases. As shown in the above image, the architecture of Microservices consists of independent smaller units, which are interconnected and managed with the help of API Gateway. Why opt for Microservices instead of Monolithic Applications? A Monolithic application is a big container with a collection of different smaller independent parts combined and coupled tightly together, which creates varied inseparable disadvantages. Here are a few disadvantages of Monolithic services. \u2022 Inflexible \u2013 Monolithic applications cannot be built using different technologies. \u2022 Unreliable \u2013 One bug or issue in the application may result in the shutdown of the entire system. \u2022 Not Scalable \u2013 The tightly coupled nature of a Monolithic application does not scale easily, as workloads cannot be easily distributed across multiple nodes or hardware. \u2022 Hinders continuous deployment \u2013 Continuous delivery and deployment in short cycles of time is difficult due to the monolithic nature of the application \u2022 Longer development timelines \u2013 The development of Monolithic applications requires lengthy timelines since every feature demands rebuilding of the entire application. \u2022 Complex applications \u2013Incorporating changes in complex monolithic applications become expensive and a maintenance nightmare. As mentioned earlier, a microservices application is a collection of small independent services designed for different business purposes. In Microservices, each individual service is self-contained. Communication with each self-contained unit is managed by an API Gateway. There are various API Gateways available, and the client can communicate with different business functions of Microservices via the API Gateway. Features of Microservices \u2022 Decoupled Components \u2013 Decoupled services in Microservices architecture enables the entire application to be built, modified, and scaled up quickly with ease. \u2022 Componentization \u2013As each service is an independent component, they can be easily individually replaced and upgraded. \u2022 Undivided business capability \u2013Each Microservice is effortless and focuses on a single business capability \u2022 Autonomy \u2013 Developers and teams can work with minimal dependencies, thus increasing development speed and turnaround time. \u2022 Continuous delivery \u2013 Allows frequent releases of features by systematic automation of application creation, testing, and approval. \u2022 Responsibility \u2013 Microservices treat applications as products and not projects, ensuring the responsibility is in-built. \u2022 Decentralized governance \u2013 With no fixed or standardized tool or any technology patterns, developers have the freedom to choose tools based on the requirements to accomplish the job within stipulated timelines. \u2022 Agility \u2013 New features can be added easily and quickly developed. A Microservices architecture supports agile development. Advantages of Microservices \u2022 Independent development \u2013 all services are independent of their business purposes and usage. \u2022 Independent deployment \u2013The architecture of Microservices allows services to be individually deployed. \u2022 Isolation of fault \u2013 the system continues to function even if one service or a part of the application ceases to work. \u2022 Mixed technologies stack \u2013 it is not mandatory to use only one of the platforms for development. We can use multiple platforms and built Microservices architecture as per the need of the application. \u2022 Individual scaling \u2013 scale different individual components and deploy them individually without affecting other components. Best Practices to Design Microservices \u2022 Separate data store for each Microservices \u2022 Maintain the level of code maturity \u2022 Separate build for each Microservice \u2022 Deploy services into containers \u2022 Treat server as stateless Disadvantages of Microservices \u2022 Huge number of services makes application management tough to track \u2022 The developer will require to solve issues pertaining to Network latency and load balancing How to create Microservices and API Gateway interface? Note: This is for those who are familiar with ASP.Net project concepts. In this demo, we'll cover the following points, 1. Create two Microservices 2. Create an API Gateway 3. For creating the demo project VS2019 or VS Code, .Net Core 3.1 SDK needs to be installed on the machine Steps to Create a Microservices Demo Project Step 1 \u2022 Create two .Net Core web API template project for different purposes \u2022 First, UserService project for user data purpose \u2022 Second, ProductService project for product data purpose \u2022 Create UserController in UserService project and ProductController in ProductService \u2022 Add simple action into the controller that returns the string for testing purpose \u2022 If required, connect API project with the database Step 2 - Test the above web API project with the help of postman individually 1.) Product Service Output 2.) User Service Output Step 3 - Create .net core web empty template project for API Gateway with the desired name. In this instance, we chose \u2018APIGateway\u2019 Step 4 - Include the dependency of ocelot API Gateway from NuGet package manager Step 5 \u2013 \u2022 Create a JSON file to configure API Gateway for web API and assign a name. In this instance, it is \u2018ocelot.json\u2019 \u2022 Include the following code text to the JSON file for configuring the API Gateway. In this demo project, API Gateway is used for routing purpose. API Gateway serves different purposes such as: o Routing o Caching o Logging o Authentication o Authorization o Load balancing o Service Discovery Note: In the above image, detail of ocelot.JSON are in the comments Some details of ocelot.JSON are considered while configuring API Gateway from the ocelot package. \u2022 The request forwarded to URL set byDownstreamPathTemplate, DownstreamHostAndPorts and DownstreamScheme \u2022 Ocelot will use the UpstreamPathTemplate URL to identify where the DownstreamPathTemplate request is to be used. \u2022 Ocelot uses UpstreamHttpMethod to make a difference between multiple requests with the same URLs but with different HTTP verbs. We can set a specific list of HTTP Methods or set a blank to allow any of them. Step 6 - Configure the JSON file for application configuration as shown below in Program.cs file Step 7 \u2013 Set Ocelot middleware ASP.Net project as shown below in Startup.cs file Step 8 \u2013 Run the application to test the working condition of API Gateway. Before running, make sure all projects are marked as startup projects. To handle request from the API Gateway application UserService and ProductService must be running. Note: If you are testing project through VS2019, the following steps will help you mark all projects as the startup project. Step 9 - Right-click on the main solution and click on the property, alter the settings as shown below Step 10 - Below screen shows the final output. When you run the project, all three startup projects will be running, at times, on different ports. We need to check if Customer and User service received a call from the API Gateway project, as shown below. Hope this article has helped you understand the know-how of Microservices. If you have any questions, please feel free to drop them in our comments section. Happy to Help! Happy Coding!