Microservices And Their Benefits

Introduction

In today’s article we will take a look at what microservices are. What is a monolith application and how are microservices different from a monolith application? What are the advantages of microservices and what are some of the drawbacks? So, let us begin.

The Monolith application

We all must have heard the term “Monolith” application many times by now. This can be defined as a single large application that covers all functionality. More than application layers (UI, Business, Data Access, Data) this type of application covers all business domains. Hence, if we look at it in terms of an HR system as below,

Microservices and their benefits

We see that all business domains or segments related to the overall HR system reside in one application. These include employee general information, departments information, payroll, tax, and vacation subsystems. This will include all application layers for each of these subsystems as well. This may be fine for smaller systems like simple POCs or applications to be used by very few users. However, as the size of these applications increases by adding new features or enhancing existing ones, scalability becomes an issue because it is an all-or-nothing type of approach. Deployment requires a complete push of the code and regression testing has to be done on the entire application each time a change is made even if only to one sub-domain piece. Hence, we see there are many limitations on a monolith application. Having said that a monolith application can be designed in a nice manner, but the issue of scalability and maintainability remain.

Microservices to the rescue

So, we have seen a number of issues in the monolith application. So, how do we solve these issues? The solution is to create microservices for the different sub-domains of our HR application. This will look as the below,

Microservices and their benefits

Here, we see that each of the sub-domains has its own service/application. Now, we can encapsulate the specific functionality of each sub-domain in its own application. These applications can be scaled independently of each other and can be updated, tested, and deployed without impacting the other services. As they are concentrated on a small domain, we call them microservices. However, we need to be very careful when we design these microservices as we do not want to be over granular or over generic. We need to make sure that related domain artifacts are placed in the same microservice. And another very important aspect is that the interfaces to interact with these services must be very clearly designed and developed.

As the UI is mostly developed using SPA frameworks or MVC Razor engines and is a very thin layer in terms of business domain implementation, I will keep that together for the main application and design my microservices at the API level. Hence, we will create a Web API application for each of the sub-domains and have endpoints for each action that we want the microservice to expose.

We will have a structure as below,

Employee and Departments Microservice

Exposed Project type: Web API with further projects for lower layers in the application

Endpoint actions

  1. Get All Departments
  2. Get List of Employees by Department
  3. Get Employee by Id

Vacation Microservice

Exposed Project type: Web API with further projects for lower layers in the application

Endpoint actions

  1. Get All Vacations
  2. Get Vacation details by Employee Id

In the next article, we will look at creating the “Employee and Department Microservice” in C#.NET and then deploy it to Azure app services. We will then look into adding logging and management for this microservice. We will not create the UI and instead, use postman to call these Web API endpoints.

Summary

In this article, we took a look at what a monolith application is? What are the problems we face with these types of applications and how they can be solved with microservices? We then looked at a simple example of an HR system that is broken down into microservices. In the next article, we will look at building one of the microservice of the HR system using C#.NET and deploying it to Azure. Happy coding!


Similar Articles