Showing 30 question(s)
Answer:
Microservices are an architectural style where an application is built as a collection of small, independent services. Each service focuses on a single business capability and communicates with other services using APIs or messaging.
Code Example:
// User Service
GET /api/users
// Order Service
GET /api/ordersAnswer:
Microservices provide independent deployment, better scalability, fault isolation, technology flexibility, faster development, and easier maintenance.
Code Example:
Benefits:
- Independent deployment
- Scalability
- Fault isolation
- Faster releasesAnswer:
A monolithic application contains all functionality in a single application, whereas Microservices split functionality into independent services that can be developed and deployed separately.
Code Example:
Monolith
Client -> Single Application
Microservices
Client -> API Gateway
|
--------------------
| User | Order | Payment |Answer:
Microservices are independently deployable, loosely coupled, highly cohesive, business-focused, scalable, and resilient.
Code Example:
Characteristics:
- Small services
- Independent deployment
- Loose coupling
- High cohesionAnswer:
Loose coupling means services depend as little as possible on each other, allowing changes in one service without affecting others.
Code Example:
User Service
|
REST API
|
Order ServiceAnswer:
High cohesion means each service focuses on a single business responsibility and contains only related functionality.
Code Example:
Inventory Service
✔ Stock Management
Payment Service
✔ Payment ProcessingAnswer:
Yes. Each Microservice should ideally own its own database to maintain independence and avoid tight coupling.
Code Example:
User Service ---> UserDB
Order Service ---> OrderDB
Product Service ---> ProductDBAnswer:
Microservices commonly communicate using REST APIs, gRPC, GraphQL, and message brokers like RabbitMQ or Kafka.
Code Example:
REST
gRPC
RabbitMQ
KafkaAnswer:
Synchronous communication occurs when one service waits for another service to respond before continuing execution.
Code Example:
Client
|
User Service
|
HTTP Request
|
Order ServiceAnswer:
Asynchronous communication allows services to exchange messages through queues or event brokers without waiting for an immediate response.
Code Example:
Order Service
|
Publish Event
|
RabbitMQ / Kafka
|
Notification ServiceAnswer:
Service-to-service communication enables Microservices to exchange data using REST APIs, gRPC, or messaging systems like RabbitMQ and Kafka.
Code Example:
User Service
|
REST API
|
Order ServiceAnswer:
REST is a synchronous communication mechanism where services exchange data using HTTP methods such as GET, POST, PUT, and DELETE.
Code Example:
GET /api/orders/1
POST /api/usersAnswer:
gRPC is a high-performance RPC framework developed by Google that uses Protocol Buffers for efficient communication between services.
Code Example:
service UserService {
rpc GetUser(UserRequest)
returns (UserResponse);
}Answer:
An API Gateway is the single entry point for clients. It routes requests to Microservices and handles authentication, authorization, rate limiting, and logging.
Code Example:
Client
|
API Gateway
| |
User OrderAnswer:
It simplifies client communication, improves security, provides centralized routing, load balancing, monitoring, and request aggregation.
Code Example:
Features
- Routing
- Authentication
- Rate Limiting
- LoggingAnswer:
Service Discovery enables services to automatically locate and communicate with each other without hardcoding addresses.
Code Example:
Order Service
|
Service Registry
|
User ServiceAnswer:
Popular Service Discovery tools include Consul, Eureka, Kubernetes DNS, and ZooKeeper.
Code Example:
Examples:
- Eureka
- Consul
- Kubernetes DNS
- ZooKeeperAnswer:
Load balancing distributes incoming requests across multiple service instances to improve availability and performance.
Code Example:
Client
|
Load Balancer
| | |
S1 S2 S3Answer:
Centralized configuration stores application settings in one place, allowing services to share and update configurations without redeployment.
Code Example:
Config Server
|
-------------
| | |
S1 S2 S3Answer:
Spring Cloud Config is a centralized configuration server that provides external configuration for distributed applications and Microservices.
Code Example:
spring:
cloud:
config:
uri: http://localhost:8888Answer:
The Circuit Breaker pattern prevents repeated calls to a failing service by temporarily blocking requests until the service recovers.
Code Example:
Client
|
Circuit Breaker
|
ServiceAnswer:
The Retry pattern automatically retries failed requests a limited number of times before reporting failure.
Code Example:
Retry 1
Retry 2
Retry 3
FailureAnswer:
Event-Driven Architecture allows services to communicate by publishing and subscribing to events instead of making direct API calls.
Code Example:
Order Service
|
Publish Event
|
Kafka / RabbitMQ
|
Notification ServiceAnswer:
RabbitMQ is a message broker that enables asynchronous communication between Microservices using queues and exchanges.
Code Example:
Producer
|
RabbitMQ
|
ConsumerAnswer:
Apache Kafka is a distributed event streaming platform used for high-throughput, fault-tolerant messaging between Microservices.
Code Example:
Producer
|
Kafka Topic
|
ConsumerAnswer:
The Saga Pattern manages distributed transactions by coordinating a sequence of local transactions with compensation steps when failures occur.
Code Example:
Order
↓
Payment
↓
Inventory
↓
ShippingAnswer:
Authentication is commonly implemented using OAuth 2.0, OpenID Connect, or JWT tokens through an API Gateway or Identity Provider.
Code Example:
Client
|
JWT Token
|
API Gateway
|
ServicesAnswer:
Centralized logging collects logs from all services into a single platform, making troubleshooting and monitoring much easier.
Code Example:
Services
| | |
------
|
ELK / GrafanaAnswer:
Containers package applications and their dependencies, ensuring consistent deployments across development, testing, and production environments.
Code Example:
Docker Build
Docker Run
Kubernetes DeployAnswer:
Keep services small and focused, use independent databases, implement API Gateway, enable centralized logging and monitoring, use asynchronous messaging where appropriate, secure APIs, automate deployments, implement health checks, and design for failure.
Code Example:
Best Practices
- API Gateway
- Health Checks
- Monitoring
- Independent DB
- CI/CD
- Docker & Kubernetes