Introduction to Microservices Architecture

Madusanka Nipunajith
The Modern Scientist
6 min readNov 25, 2022

By referring to this article, you will be able to get a better idea of the Microservice architecture and when to use it. Furthermore, this article consists of the following contents.

◼ Abbreviations of the article

◼ Introduction

◼ Microservices Ecosystem

◼ Monolith Architecture vs Microservice Architecture

◼ Challenges in Microservices

◼ When to use Microservices

Abbreviations

  • API : Application Programming Interface
  • MS : Microservice
  • NoSQL : Not only SQL
  • RTE : Runtime Environment

Introduction

Microservices architecture is an approach to application development in which a large application is built as a suite of modular services (This means that it(microservice) is a type of application architecture where the application is developed as a collection of services). Each module supports a specific business goal and uses a simple well-defined interface to communicate with other sets of services. Furthermore, there is a bare minimum of centralized management services, which may be written in different programming languages such as java, python, etc, and use different data storage technologies like relational and NoSQL in the microservices architecture.

microservices architecture
Microservices Architecture

There are some key features/characteristics of microservices as follows.

  • Highly maintainable and testable
  • Loosely coupled (communicate via an interface)
  • Independently deployable
  • Organized around business capabilities
  • Owned by a small team (cross-functional team)

Microservices Ecosystem

In general, The Microservices system contains the following listed entities. Some of these entities are phases in standard software development and some of them are Microservices specific processes which will provide the backbone for an efficient microservices system.

Load Balancer

The main responsibility of the load balancer is to distribute the incoming load among many instances of microservices. Mainly there are 2 types of load balancers called client discovery (client-side load balancer)and server discovery (server-side load balancer). In the client discovery, the client talks to the service registry and does load balancing. Because of that client need to be aware of the service registry. In the server discovery, client talks to the load balancer and the load balancer talks to the service registry. Therefore, client service need not be aware of the service registry. By looking at the following diagrams you can get more understanding of these 2 types of the load balancer.

client-side load balancer

Service Discovery server

The service discovery functionality allows microservices to self-register at startup instead of manually keeping track of what microservices deployed currently on and what hosts and ports we need. Therefore, If MS1 wants to talk with MS2, firstly, MS1 gets the details from the registry service which belongs to the landscape and then talks with MS2. Moreover, when there is another MS called MS3 that has been up or down in the same landscape the registry service will be updated automatically.

Service Discovery server

API Gateway

The API Gateway is a server. It is a single entry point into a system. API Gateway encapsulates the internal system architecture. It provides an API that is tailored to each client. It also has other responsibilities such as authentication, monitoring, load balancing, caching, request shaping and management, and static response handling.API Gateway is also responsible for request routing, composition, and protocol translation. All the requests made by the client go through the API Gateway. After that, the API Gateway routes requests to the appropriate microservice.

The API Gateway handles the request in one of two ways:

  • It routed or proxied the requests to the appropriate service.
  • Fanning out (spread) a request to multiple services.
API Gateway

Monitoring

Now we know there are a lot of microservices running on different nodes in the same ecosystem.Therefore, we need to monitor them together in a single system is essential.Hystrix dashboard and Spring boot admin dashboard are some examples of monitoring tools. There are five principles of monitoring microservices as follows:

  • Monitor containers and what’s inside them.
  • Alert on service performance.
  • Monitor services that are elastic and multi-location.
  • Monitor APIs.
  • Monitor the organizational structure
Monitoring

Containerization

When we are implementing microservices they are running on different RTEs such as JRE and Node.js as the implementation of the microservices can be done using different technologies. Also, you know that these microservices are deployed in a polyglot manner. Hence nodes don’t know the RTE of the deployed microservice and we need to install it manually in each node. But when it comes to Containerization, we package our RTE with our microservice. Therefore we can run the microservices everywhere without considering the RTE and we can manage and update these services easily.

Containerization

Circuit Breaker

Circuit Breaker

It is a very important entity in the microservices’ ecosystem. Most of the time this is defined as a pattern. For understanding purposes, this is pretty much similar to your home’s circuit breaker. It protects you from disaster and it stops the propagation of the problem that arose. The same scenario is happening here (circuit breaker in MS) with respect to the microservices. Let’s assume that the client sends a request to the supplier microservice and while the response is coming there is a connection problem. Because of that client is waiting for a response for a long time and it might affect to other services as well. Since the circuit breaker architecture, the problematic channel is discarded and the previous waiting issue is solved. Moreover, there are three different States of Circuit Breaker called Closed, Open and Half Open.

Monolith Architecture vs Microservice Architecture

Monolith Architecture vs Microservice Architecture
Monolith Architecture vs Microservice Architecture

Price

  • Monolithic : Higher once the project scales
  • Microservce : Higher at the first development stage

Coding

  • Monolithic : A united codebase and database for the entire product
  • Microservce : Multiple code files; each service handles a base and a data storage

Deployment

  • Monolithic : The entire code base needs to be deployed
  • Microservce : Each microservice is deployed individually

Tech stack

  • Monolithic : The same code stack
  • Microservce : Different stacks (language, runtime environment and etc)

Challenges in Microservices

There are some challenges when we are dealing with microservices as follows.

  • Inter-process communication (via network)
  • Distributed transactions
  • A Large number of services
  • Require more automation

When to use Microservices

Now we have a good understanding of microservices and their challenges. Let’s see which scenarios are suitable to go with microservices.

  • The company wants to build clean, readable code right away and avoid technical debt
  • The company has human resources for microservices development
  • The company prioritizes long-term gains over short-term benefits
  • A team of developers uses different tech stacks and tools
  • The platform has to be highly scalable and expand to different markets

In this article, I discussed the Microservice architecture, its structure, how microservice is differ from monolith architecture and etc. I hope this might help anyone who is stepping into the Microservices world. Thank you! 😊 ✌

--

--

Madusanka Nipunajith
The Modern Scientist

Undergraduate at UCSC, Former SAP Team Leader, Former Math Instructor, Former SE (Intern) at WSO2