0% found this document useful (0 votes)
3 views8 pages

Micro Services

Microservices architecture is a design approach that structures applications as a collection of small, independent services that communicate through various methods, such as APIs and events. It includes different types based on design patterns, deployment strategies, and communication models, as well as tools like service registries and circuit breakers to enhance functionality. Additionally, client-side and server-side microservices differ in how they manage data and API calls, while load balancers and service discovery mechanisms ensure efficient traffic distribution and service communication.

Uploaded by

saundaraditya1
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
3 views8 pages

Micro Services

Microservices architecture is a design approach that structures applications as a collection of small, independent services that communicate through various methods, such as APIs and events. It includes different types based on design patterns, deployment strategies, and communication models, as well as tools like service registries and circuit breakers to enhance functionality. Additionally, client-side and server-side microservices differ in how they manage data and API calls, while load balancers and service discovery mechanisms ensure efficient traffic distribution and service communication.

Uploaded by

saundaraditya1
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd

Q1)What is the Microservices Architecture?

Microservices architecture involves designing applications as a collection of small,


independent services that communicate with each other. Several design patterns
help build and organize these services effectively. Here are some key types of
microservices architecture and design patterns:
Types of Microservices Architecture
Microservices architecture can be categorized based on design patterns,
deployment strategies, and communication models. Here are the most
common types:
1. Based on Design Patterns
a) API-Driven Microservices
 Each microservice exposes its functionality via APIs (typically REST or
GraphQL).
 Clients interact with services via an API Gateway.
 Example: Netflix API Gateway.
b) Event-Driven Microservices
 Services communicate asynchronously using events.
 Uses message brokers like Kafka, RabbitMQ, or AWS SQS.
 Example: A payment service listening for an "order placed" event before
processing payments.
2. Based on Deployment Strategies
a) Monolithic Deployment (Modular Approach)
 Microservices are modular but deployed together in a single package.
 Suitable for small-scale projects transitioning to microservices.
b) Service Instance per Host
 Each service runs on a separate virtual machine (VM).
 Example: AWS EC2 instances for each microservice.
c) Service Instance per Container
 Each service runs inside a Docker container, managed by Kubernetes.
 Most common approach for modern cloud applications.
d) Serverless Microservices
 Microservices run in serverless environments (AWS Lambda, Azure
Functions).
 Services scale automatically and are event-driven.
3. Based on Communication Models
a) Synchronous Microservices (Request-Response Model)
 Services communicate using HTTP REST, gRPC, or GraphQL.
 Suitable for real-time transactions (e.g., fetching user profiles).
b) Asynchronous Microservices (Event-Driven Model)
 Services communicate using message queues (Kafka, RabbitMQ).
 Useful for event-driven workflows (e.g., Order → Payment → Notification).

4. Service Registry
 Purpose: Keeps track of all the services in the system, making it
easier for them to find each other.
 Example: Eureka in Netflix OSS.
[Link] Breaker
 Purpose: Prevents a failure in one service from cascading to other
services by stopping the flow of requests to the failing service.
 Popular Implementations:
✅ Resilience4j (Modern, lightweight)
✅ Hystrix (Netflix OSS) (Deprecated)
✅ Sentinel (Alibaba)
 Example: Hystrix in Netflix OSS.
[Link] Pattern
 Purpose: Manages distributed transactions by breaking them into a
series of smaller, manageable transactions.
 Example: Coordinating order processing in an e-commerce system.
Q2)What are client side and server side microservices
Client-Side vs. Server-Side Microservices
Microservices architecture involves multiple small, independent services working
together. The distinction between client-side and server-side microservices is
based on how services communicate and where the orchestration happens.

1. Client-Side Microservices
In client-side microservices, the client (e.g., a web or mobile app) directly
communicates with multiple microservices. The client is responsible for aggregating
and managing data from different services.
Example Architecture:
 A React frontend calls multiple backend services (e.g., User Service, Order
Service, Payment Service).
 The frontend handles orchestration, meaning it decides what data to fetch
and how to combine it.
Pros:
i)Reduces the need for an additional middle layer (API Gateway).
ii)Faster for small applications with fewer services.
iii)Simple implementation in some cases.
Cons:
i)The client must handle multiple API calls, increasing complexity.
ii)Harder to manage authentication, retries, and error handling.
iii)Not efficient for mobile apps (increases latency).
Example (Client Fetching Multiple Services)
js
Copy code
// React app making multiple API calls
useEffect(() => {
async function fetchData() {
const users = await fetch("/api/users").then(res => [Link]());
const orders = await fetch("/api/orders").then(res => [Link]());
[Link](users, orders);
}
fetchData();
}, []);

2. Server-Side Microservices
In server-side microservices, a backend API Gateway or a BFF (Backend for
Frontend) aggregates responses from multiple microservices before sending them
to the client.
Example Architecture:
 The frontend makes a single API call to an API Gateway (e.g., GraphQL
Server, [Link] Aggregator, or Spring Boot API Gateway).
 The API Gateway calls multiple microservices, aggregates the data, and
returns a single response.
Pros:
i)Reduces complexity for the client (single API call).
ii)Improves performance (especially for mobile devices).
iii)Centralized authentication and error handling.
Cons:
i)Slightly more complex backend setup.
ii)Gateway can become a bottleneck if not optimized.
Example (API Gateway Aggregating Responses)
js
Copy code
// API Gateway ([Link]) aggregating multiple services
[Link]("/api/combined", async (req, res) => {
const users = await fetch("[Link] => [Link]());
const orders = await fetch("[Link] =>
[Link]());
[Link]({ users, orders });
});

Key Differences
Feature Client-Side Microservices Server-Side Microservices

API Calls Multiple calls from client Single call from client

Data Done on the client Done on the server


Aggregation

Performance Slower for mobile (high Faster (less client processing)


latency)

Error More complex on client Centralized error handling


Handling

Best for Small apps, web-based Large apps, mobile-first


frontends applications

Which One Should You Use?


 Use client-side microservices if you have a simple app with fewer services.
 Use server-side microservices if you have many services, want better
performance, and need centralized authentication.

Q3)What is load balancer why we use it


A load balancer is a system that distributes incoming network traffic across
multiple servers (or microservices) to ensure no single server is overwhelmed. It
helps improve performance, availability, and fault tolerance in applications.

Why Do We Use a Load Balancer?


1. Scalability – Distributes traffic among multiple servers, allowing systems to
handle more users.
2. High Availability – If one server fails, traffic is redirected to healthy servers.
3. Improved Performance – Balances requests to avoid slow response times.
4. Security – Can protect against DDoS attacks by managing traffic efficiently.
5. Session Persistence – Ensures requests from the same client go to the
same server when needed.

Types of Load Balancers


1. Layer 4 Load Balancer (Transport Layer - TCP/UDP)
o Routes traffic based on IP address and port.
o Faster but less flexible.

o Example: AWS Elastic Load Balancer (ELB), Nginx TCP Load Balancing.

2. Layer 7 Load Balancer (Application Layer - HTTP/HTTPS)


o Routes traffic based on URL, headers, cookies (e.g., /api/orders goes
to Order Service).
o More intelligent but slightly slower.

o Example: Nginx, HAProxy, AWS ALB (Application Load Balancer).

Q4)What is Service Discovery in Microservices?


Service Discovery is a mechanism that automatically detects and manages
microservices in a distributed system. It allows services to find and
communicate with each other without hardcoding network locations.

Types of Service Discovery


1️) Client-Side Service Discovery
 The client queries a Service Registry to get the service location.
 Example: Netflix Eureka, Consul
✅ How it Works:
 Service registers itself with the Service Registry.
 Client requests the registry for the service location.
 Client directly calls the service.

2) Server-Side Service Discovery


 The client requests a Load Balancer (e.g., API Gateway), which queries
the Service Registry.
 Example: AWS Route 53, Kubernetes Kube-DNS, Nginx
✅ How it Works:
 Service registers with the Registry.
 Client sends a request to API Gateway.
 The gateway retrieves the service location and forwards the request.

Feature Client-Side Discovery Server-Side Discovery

Who finds the The client The load balancer/API


service? Gateway

Example Tools Eureka, Consul Kubernetes, AWS Route 53

Best for Small apps, lightweight Large, scalable


services deployments

Q5)What is a Circuit Breaker and give me a name


A Circuit Breaker is a fault-tolerance mechanism in microservices that prevents
repeated failures due to an unavailable or slow service.
📌 Why Needed?
 In a microservices architecture, services communicate over a network.
 If one service fails or becomes slow, other services may keep retrying
indefinitely.
 This can overload the system and cause a cascading failure.
 Circuit Breaker prevents this by stopping requests to a failing service
after a threshold.

Circuit Breaker Type

Circuit Breaker How It Works When to Use


Type

Count-Based Tracks N failed requests in a When failure patterns


fixed window are consistent

Time-Based Tracks failures over time When failures are time-


(e.g., last 30 sec) sensitive

Threshold- Opens after X consecutive When failures happen


Based failures suddenly

Hybrid (Count Uses both count & time For adaptive failure
+ Time) tracking handling

Best Circuit Breaker Tools

Tool Status Used With

Netflix Hystrix Deprecat Spring Boot,


ed Java

Resilience4j Active Java, Spring


Boot

Sentinel Active Alibaba Cloud

Istio Circuit Active Kubernetes


Breaker

You might also like