Microservice Architecture Explained

Rajesh Srivastava
6 min readApr 23, 2020

So, What is a Microservice Architecture? It’s one of my favorite routine questions I usually ask at every interview. To my surprise (not always, of course), the answer revolves around how we can build Microservices using preferred language and then deploy to cloud using CI/CD pipeline and — boom we have production-ready microservice. Many times, even Senior Engineers — with substantive years of experience — fail to provide a broader perspective.

However, the implementation is not as simple as it looks. With Microservices, the business does not remain as conventional as Monolith applications coz’ we need to develop-manage and monitor a hundred to thousands of services than a few ones. Surely, with a broader range of benefits and a sense of ownership.

It is likely that individuals have worked one or another aspect of microservice but did not venture into end-to-end implementation. But with DevOps culture, it’s imperative to involve yourself in Development and Operations together.

Isn’t DevOps growing popular and widely adopted by many organizations for that purpose?

The idea of this series is to cover more of the microservice’s end-to-end implementation — excuse me for this part where context and concept require to head start. Let’s deep-dive into Microservice’s world.

Microservices — also known as the microservice architecture — is an architectural style that structures an application as a collection of services that are highly maintainable and testable , Loosely coupled, Independently deployable,Organized around business capabilities, Owned by a small team.”

By “Chris Richardson” author of POJOs in Action

High-Level Microservice Architecture

If you analyze the above diagram, you will find many moving pieces that coordinate together and work as a whole system. Let’s explain them one by one in the context of Microservice Architecture.

Client — It can be a Mobile App, SPA Web App (TypeScript languages like ReactJS & Angular), or traditional Web App. The request to downstream should be passed through lightweight and human-readable JSON (JavaScript Object Notation).

CDN (Content Delivery Network) — CDN is a system of distributed servers or networks of servers in locations all over the world. It delivers content from the website or mobile application to people more quickly and efficiently, based on the geographic locations of the user, the origin of the webpage, and the content delivery server.

Load Balancer (Hardware/Software) — If there is a high value of incoming traffic and it is affecting system performance and ultimately user experience, application traffic needs to be distributed evenly and efficiently at multiple servers in a server farm.

The load balancer sits between client devices and backend servers, receiving and then distributing incoming requests to any available server based on the load balancing algorithm such as Round Robin, Weighted Round Robin, Random, Least Connection, Weighted Least Connection, etc.

Web Apps — Can be hosted on any web server clusters — like Apache, Tomcat, Heroku, etc — for the traditional web apps.

API Gateway (Zuul, APIGEE, etc) — It’s a server that is the single entry point into the system and hitting microservices. It is responsible for Authentication & Authorization, request routing, rate limiting, spike arrest, JWT validation, CORS validation, composition, and protocol translation.

It must be horizontally scaled to avoid the single point of failure.

Any request coming from clients first go through the API Gateway after that it routes requests to the appropriate microservice.

Service Discovery (Eureka, Consul, etc) — Service Discovery solution like Eureka is a REST-based service that holds information about all client-service applications.

Every Microservice will register into the Eureka server and the Eureka server knows all the client applications running on each port and IP address. It’s also known as Discovery Server.

We can implement client-side load balancing using Spring Cloud Ribbon and Eureka server. In that multiple instances of a microservice register at Eureka and any request coming from API Gateway load balanced and routed to any available instance of service.

The benefit of using Service Discovery is that in case of any instance goes down it will be de-registered from the Service Discovery to avoid request routing to that instance. The same holds for adding a new instance where the request can be routed to a new instance.

With the help of Service Discovery, we can horizontally scale services without restarting any service.

Management — Management Endpoints (Spring Boot Actuator endpoints) allow you to monitor and interact with your application. Spring Boot includes several built-in endpoints and you can also add your own.

Like, the health endpoint provides basic application health information. It’s widely used by containers to check the health and other parameters of the application.

Microservices — These microservices are designed around business capabilities, can be deployed independently on the public/private cloud using CI/CD pipeline and loosely coupled. It should be designed for stateless computing, resiliency, and failure.

Communication among themselves happens through lightweight rest based calls. They are the heart of whole architecture and everything focused around them.

Event Bus (Publis/Subscribe channel) — It’s a publish/subscribe channel that works as an event bus with RabbitMQ/Kafka messaging/streaming system for async tasks notification. For any notification task, we can have a worker thread that will work asynchronously.

This substantially reduces blocking calls and thus improving user experience and performance.

It supports Event-Driven-Architecture, which is one of the popular ways to handle asynchronous requests apart from the rest based protocol.

Telemetry and Monitoring (ELK, Splunk, Grafana, AppDynamics) — Because of numerous loosely coupled microservices, observability and monitoring remain a critical part to manage microservices.

Microservices based applications have different and more intensive monitoring requirements.

The services communicate with each other using rest based calls and requests typically span multiple services instances. In case of any failure, we need to trace the log across services, and this is where different monitoring tools help for log management, application performance management.

ELK Stack is one of the open-source solutions, where Logstash, collects and aggregates logs that are indexed by Elasticsearch and searched via a Kibana dashboard. Other tools like Splunk, Grafana, AppDynamics, etc are also widely used for the same purpose.

Caching — For heavily read-data, caching is used frequently at various layers. For example, at the client end, at the API Gateway and across multiple instances of the service. It’s used as placing copies of data in a temporary storage location so that it can be accessed quickly.

It improves app performance and also protects the network from the flux of additional traffic.

We can use in-memory or external storage based cache — Redis, Memcache, Ehcache, Hazlecast, Caffeine, etc — as per our requirement at different layers. One should be careful about the implementation of the write cache policy to avoid stale cache while using caching.

With this, here ends a bird’s eye view of Microservices Architecture. There is a lot to do in terms of making your microservices genuinely cloud-native. Like,

  • CI/CD pipeline automation
  • On-premise, and Public Cloud deployment and Scaling of services
  • Externalized Configuration
  • Resiliency-Fault tolerance & Self-healing (Circuit Breaker, Retry, Fallback, etc)
  • Automation of Functional, and Behavioural Test cases, Automation of infrastructure, etc.

The Twelve-Factor App methodology is a set of best practices to build a great cloud-native application. Some of those are mentioned before. I will cover all the above points in detail in the upcoming parts as it necessitated more elaboration.

Watch for this space for the next part where I will explain an end-to-end implementation of Microservices with API Gateway, Service Discovery, and other stacks. Till then happy learning 😊 .

--

--