Skip to main content

Introduction to Microservices

Introduction to Microservices - Concepts


Microservices are currently getting a lot of attention now a days. Everyone wants to shifts to micro-service architecture. But what exactly is micro-service Architecture and why do we need it.

The central idea behind microservices is that some types of applications become easier to build and maintain when they are broken down into smaller, composable pieces which work together. Each component is continuously developed and separately maintained, and the application is then simply the sum of its constituent components. This is in contrast to a traditional, "monolithic" application which is all developed all in one piece.


Monolithic Architecure


So this is what microservice architecture is. If this is not making much sense now, lets first understand what monolithic architecture is : 
  • Lets say I have a big project which consists of different conceptual modules like User, QnA, Product, Orders 
  • In a monolithic architecture, we will just one codebase.
  • That codebase will have all code related to all modules. And its not like that monolithic architecture is something which is wrong. 
  • For small projects even I would prefer monolithic architecture.
  • But the actual issue arises when the number of modules increases significantly.

The issues that could arises because of monolithic architecture are :
  • It will be difficult to manage the codebase.
  • Monolithic applications can also be difficult to scale when different modules have conflicting resource requirements.
  • Monolithic applications has a barrier to adopting new technologies. Since changes in frameworks or languages will affect an entire application it is extremely expensive in both time and cost.
  • Another problem with monolithic applications is reliability. Bug in any module (e.g. memory leak) can potentially bring down the entire process. Moreover, since all instances of the application are identical, that bug will impact the availability of the entire application.
  • You must redeploy the entire application on each update.
  • Impact of a change is usually not very well understood which leads to do extensive manual testing.


Microservice Architecture
Now what microservices architecture says that we divide our application in small independent services which works independently and ideally do not communicate with each others. This could be said that A service has no knowledge about B Service.

Basically the idea is to split your application into a set of smaller, interconnected services instead of building a single monolithic application. Each microservice is a small application that has its own hexagonal architecture consisting of business logic along with various adapters. Some microservices would expose a REST, RPC or message-based API and most services consume APIs provided by other services. 


Also not only codebase, complete microservice architecture says each service will have its own database and that database access is limited to particular service only.

Benefit of Microservices
  • It tackles the problem of complexity by decomposing application into a set of manageable services which are much faster to develop, and much easier to understand and maintain.
  • It enables each service to be developed independently by a team that is focused on that service.
  • It reduces barrier of adopting new technologies since the developers are free to choose whatever technologies make sense for their service and not bounded to the choices made at the start of the project.
  • Microservice architecture enables each microservice to be deployed independently. As a result, it makes continuous deployment possible for complex applications.
  • Microservice architecture enables each service to be scaled independently.
Drawbacks of Microservices
  • Using micro-service architecture, meaning we are now using distributed system. So now there will be calls to various services at some facade layer(Aggregation layer), where we need to handle RPC and Services calls failure.
  • Testing the architecture becomes difficult.
  • Major issue comes when debugging the issue. To debug the issues, we need something to link calls between different services(done via distributed tracing).
  • Now in micro-services, our database are also partitioned. Now if some business requirement is like that that need transactions between various services then we need to take care of distributed transactions(SAGA Pattern).
  • Now you to monitor and manage multiple applications.

Comments