Micro Services
Micro Services
10/04/24 2:23 PM
Design Patterns:
○ API gateway pattern
○ Service discovery pattern
○ Circuit breaker pattern
○ Blue-green deployment pattern
○ Message Brokers: (Apache Kafka, RabbitMQ, Apache Pulsar, and AWS SQS/SNS)
Message brokers facilitate asynchronous communication between microservices using messaging or event-driven
architecture.
They provide features such as pub/sub messaging, message queues, durability, fault tolerance, and scalability.
○ Service Discovery: (Consul, Eureka (part of Netflix OSS), ZooKeeper, and AWS Cloud Map)
Service discovery tools help microservices locate and communicate with each other dynamically without hardcoding
network addresses.
They provide features such as service registration, service lookup, health checks, and load balancing.
○ Load Balancers: (HAProxy, NGINX, AWS ELB (Elastic Load Balancer), and Kubernetes Ingress)
Load balancers distribute incoming client requests across multiple instances of microservices to improve scalability,
availability, and performance.
They provide features such as traffic distribution, health checks, and session persistence.
○ REST Clients and Libraries: (Spring RestTemplate, Feign, Retrofit, and Apache HttpClient)
REST clients and libraries help microservices communicate with each other over HTTP/RESTful APIs.
They provide features such as HTTP request/response handling, serialization/deserialization, and error handling.
○ Service Mesh: (Istio, Linkerd, Consul Connect, and AWS App Mesh)
A service mesh is a dedicated infrastructure layer that facilitates communication between microservices.
It provides features such as service discovery, load balancing, encryption, traffic routing, circuit breaking, and
observability.
Coupling:
It is defined as a relationship between software modules A and B, and how much one module depends or interacts with
another one. Couplings fall into three major categories. Modules can be highly coupled (highly dependent), loosely coupled,
and uncoupled from each other. The best kind of coupling is loose coupling, which is achieved through interfaces.
Cohesion:
It is defined as a relationship between two or more parts/elements of a module that serves the same purpose. Generally, a
module with high cohesion can perform a specific function efficiently without needing communication with any other
modules. High cohesion enhances the functionality of the module.
Example: Suppose we have a class that multiplies two numbers, but the same class creates a pop-up window
displaying the result. This is an example of a low cohesive class because the window and the multiplication operation don’t
have much in common. To make it high cohesive, we would have to create a class Display and a class Multiply. The Display
will call Multiply’s method to get the result and display it. This way to develop a high cohesive solution.
12 Factor rules:
○ Codebase (One codebase tracked in revision control, many deploys)
In Microservices, every service should have its own codebase. Having an independent codebase helps you to easy
CI/CD process for your applications.
○ Dependencies (Explicitly declare and isolate the dependencies)
All the application packages will be managed through package managers like sbt, maven.
▪ In non-containerized environments, you can go for configuration management tools like chef, ansible, etc. to
install system-level dependencies.
▪ For a containerized environment, you can go for Dockerfile.
Idempotence:
The term 'idempotence' refers to the repeated performance of a task despite the same outcome. In other words, it is a
situation in which a task is performed repeatedly with the end result remaining the same.
When an HTTP method is idempotent in a REST API, this means that if you send multiple identical requests, only the
initial request would cause a change. Therefore, the results returned to the user will not depend on how many times the
method has been called.
Usage: When the remote service or data source receives instructions more than once, Idempotence ensures that it will
process each request once.