Chapter 11 — Microservices Interview Questions (30+ Questions)
Microservices are one of the most common topics for Senior Software Engineer / Lead Developer interviews, especially for .NET, Java, and cloud positions.
Interviewers usually evaluate:
- architecture knowledge
- distributed system understanding
- cloud experience
- communication patterns
- reliability strategies
- deployment practices
1. What are microservices?
Interview Answer
Microservices are an architectural style where an application is divided into small, independent services. Each service focuses on a specific business capability and can be developed, deployed, and scaled independently.
Example
E-commerce application:
Monolith:
+--------------------------------+
| Application |
| |
| Product |
| Orders |
| Payments |
| Users |
| Reports |
| |
+--------------------------------+
Microservices:
API Gateway
|
+-----------+-----------+-----------+
Product Order Payment User
Service Service Service Service
Each service:
- owns its logic
- has its own database
- can be deployed separately
Example in .NET
Services:
ProductService
ASP.NET Core Web API
OrderService
ASP.NET Core Web API
PaymentService
ASP.NET Core Web API
Communication:
REST API
gRPC
RabbitMQ
Kafka
Azure Service Bus
Senior Answer
Microservices are independently deployable services organized around business capabilities. They improve scalability and team autonomy but introduce distributed system challenges such as communication, monitoring, and data consistency.
2. What are the advantages of microservices?
Interview Answer
Microservices provide several benefits compared with a traditional monolithic architecture.
1. Independent Deployment
A single service can be updated without deploying the entire application.
Example:
Before:
Change Payment Logic
|
Deploy Entire Application
After:
Change Payment Service
|
Deploy Payment Service Only
2. Independent Scaling
Different services have different workloads.
Example:
Order Service
100 instances
User Service
5 instances
3. Fault Isolation
Failure in one service does not necessarily stop the whole system.
Example:
Recommendation Service DOWN
|
Shopping still works
4. Technology Flexibility
Different services can use different technologies.
Example:
Order Service
.NET
Analytics Service
Python
5. Team Independence
Different teams can own different services.
Senior Answer
The main benefits of microservices are independent deployment, independent scaling, fault isolation, and better alignment between teams and business domains.
3. What are the disadvantages of microservices?
Interview Answer
Microservices solve many problems but introduce additional complexity.
1. Distributed System Complexity
Communication becomes network-based.
Example:
Order Service
|
Network Call
|
Payment Service
Possible problems:
- timeout
- network failure
- latency
2. Data Consistency
Each service may have its own database.
Example:
Order DB
Payment DB
Inventory DB
Maintaining consistency becomes harder.
3. Deployment Complexity
Many services require:
- CI/CD pipelines
- containers
- orchestration
4. Monitoring Complexity
Need:
- centralized logging
- tracing
- metrics
5. Testing Complexity
Need:
- integration testing
- contract testing
Senior Answer
Microservices increase scalability and flexibility but introduce challenges around distributed communication, data consistency, deployment, monitoring, and operational complexity.
4. Monolith vs Microservices — what is the difference?
Interview Answer
A monolith is a single application containing all functionality. Microservices split functionality into independent services.
Monolith
Architecture:
Client
|
Single Application
|
Database
Advantages:
- simple development
- easy deployment
- easier debugging
Disadvantages:
- difficult scaling
- large codebase
- tight coupling
Microservices
Architecture:
Client
|
API Gateway
|
+---------+---------+---------+
User Order Payment Product
Service Service Service Service
Advantages:
- independent scaling
- independent deployment
- better isolation
Disadvantages:
- complexity
- network communication
- operational overhead
Senior Answer
Monoliths are simpler and work well for smaller applications, while microservices are better for large systems requiring independent scaling, deployment, and team ownership.
5. When should you NOT use microservices?
Interview Answer
Microservices are not always the best solution.
Avoid microservices when:
1. Small Application
Example:
Internal company tool
10 users
A monolith is usually better.
2. Small Team
Example:
2 developers
Managing many services creates unnecessary overhead.
3. Simple Domain
If business logic is simple:
CRUD Application
Microservices add complexity.
4. Lack of DevOps Maturity
Microservices require:
- automation
- monitoring
- deployment pipelines
Senior Answer
I choose microservices based on business needs, not because they are popular. For smaller systems a modular monolith is often a better choice.
6. What is a service boundary?
Interview Answer
A service boundary defines what responsibility belongs to a particular microservice.
A good service boundary usually follows business capabilities.
Bad design:
Customer Service
- Save Customer
- Calculate Invoice
- Process Payment
- Manage Inventory
Too many responsibilities.
Better:
Customer Service
Customers
Billing Service
Invoices
Payment Service
Transactions
Example
E-commerce domain:
Customer
Order
Inventory
Payment
Shipping
Each becomes a separate business capability.
Senior Answer
Service boundaries should be based on business domains rather than technical layers. Each service should own a specific capability and minimize dependencies on other services.
7. What is Domain-Driven Design (DDD)?
Interview Answer
Domain-Driven Design is an approach where software architecture is organized around business domains and concepts.
Important DDD concepts:
Domain
Business area.
Example:
Banking
Trading
Insurance
Entity
Object with identity.
Example:
Customer
CustomerId = 123
Value Object
Object defined by its value.
Example:
Money
Amount: 100
Currency: CAD
Aggregate
Group of related objects managed together.
Example:
Order Aggregate
Order
Order Items
Customer Reference
Bounded Context
A clear boundary around a model.
Example:
Sales Context
Customer means buyer
Support Context
Customer means ticket owner
Senior Answer
DDD helps design microservices by identifying business boundaries and creating services around bounded contexts rather than technical components.
8. What is a bounded context?
Interview Answer
A bounded context is a boundary where a specific domain model applies.
The same word may have different meanings in different contexts.
Example:
Company system:
Sales Context
Customer:
Person who buys products
Support Context
Customer:
Person who submits tickets
Billing Context
Customer:
Person responsible for payment
Architecture:
+-------------+
Sales Context
+-------------+
|
+-------------+
Billing Context
+-------------+
|
+-------------+
Support Context
+-------------+
Why important?
Without boundaries:
One giant Customer object
with 200 properties
becomes difficult to maintain.
Senior Answer
Bounded contexts prevent domain models from becoming too coupled. In microservices, each service typically owns a bounded context.
9. What is API Gateway pattern?
Interview Answer
API Gateway provides a single entry point for clients and routes requests to backend services.
Architecture:
Client
|
API Gateway
/ | \
User Order Payment
Service Service Service
Responsibilities:
Routing
Example:
/users
|
User Service
/orders
|
Order Service
Authentication
Example:
JWT validation
before reaching services
Rate Limiting
Example:
1000 requests/minute
per user
Logging
Central request tracking.
Examples:
.NET:
- Ocelot
- YARP
Cloud:
- AWS API Gateway
- Azure API Management
Senior Answer
API Gateway centralizes cross-cutting concerns such as routing, authentication, rate limiting, and monitoring while hiding internal service complexity from clients.
10. What is service discovery?
Interview Answer
Service discovery allows services to find each other dynamically without hard-coded addresses.
Problem:
Without discovery:
Order Service
calls
http://10.0.0.25:5000
If the server changes:
Address invalid
With service discovery:
Order Service
|
Service Registry
|
Payment Service Address
Example:
Payment Service
Instances:
10.0.0.5
10.0.0.6
10.0.0.7
Types
Client-Side Discovery
Client asks registry.
Example:
Order Service
|
Consul
|
Payment Instance
Server-Side Discovery
Load balancer performs discovery.
Example:
Client
|
Load Balancer
|
Service Instances
Tools
- Consul
- Eureka
- Kubernetes Service Discovery
- AWS Cloud Map
Senior Answer
Service discovery enables dynamic communication between microservices by maintaining information about available service instances and their locations.
End of Chapter 11 — Microservices
Covered:
✅ What are microservices
✅ Advantages
✅ Disadvantages
✅ Monolith vs Microservices
✅ When not to use microservices
✅ Service boundaries
✅ Domain-Driven Design
✅ Bounded Context
✅ API Gateway
✅ Service Discovery
11. What is the Database per Service pattern?
Interview Answer
The Database per Service pattern means each microservice owns its own database and is responsible for managing its own data.
Architecture
API Gateway
|
+-------------+-------------+
| | |
Order Service Payment Service User Service
| | |
Order DB Payment DB User DB
Example
Order Service:
Order Database
Orders
OrderItems
OrderStatus
Payment Service:
Payment Database
Transactions
Payments
Refunds
Why use it?
1. Service Independence
A service can change its database technology.
Example:
Order Service
SQL Server
Analytics Service
MongoDB
2. Better Security
Services only access their own data.
3. Independent Scaling
Example:
Payment database may need more resources than User database.
Challenges
Data Consistency
Example:
Order created:
Order DB
Order = Created
Payment DB
Payment = Pending
Need events to synchronize.
Cross-Service Queries
Example:
"Show customer orders with payment status"
Cannot simply use SQL JOIN.
Solutions:
- API composition
- CQRS
- replicated read models
Senior Answer
Database per Service improves service independence and scalability but requires careful handling of distributed transactions, data consistency, and cross-service reporting.
12. Shared Database vs Database per Service
Interview Answer
These are two different approaches for storing microservice data.
Shared Database
Architecture:
Services
|
|
Shared Database
Example:
Order Service
Payment Service
User Service
|
SQL Server
Advantages
- simple
- easy reporting
- easier transactions
Disadvantages
- strong coupling
- difficult independent deployment
- schema changes affect multiple services
Database per Service
Architecture:
Order Service
|
Order DB
Payment Service
|
Payment DB
Advantages
- independence
- scalability
- ownership
Disadvantages
- complex queries
- distributed transactions
Senior Answer
For small systems, a shared database can be practical. For large enterprise systems, I prefer database-per-service because it provides stronger service boundaries and independent scalability.
13. How do microservices communicate?
Interview Answer
Microservices communicate using synchronous or asynchronous communication.
Synchronous Communication
Usually:
- REST
- gRPC
Example:
Order Service
HTTP Request
|
Payment Service
Response
Use when:
- immediate response required
- simple request-response scenarios
Example:
Check customer profile.
Asynchronous Communication
Using:
- RabbitMQ
- Kafka
- Azure Service Bus
- AWS SQS
Example:
Order Service
|
OrderCreated Event
|
Message Broker
|
Inventory Service
Use when:
- high scalability needed
- services should be loosely coupled
Senior Answer
I use synchronous communication for immediate operations and asynchronous messaging for long-running processes, event propagation, and reducing coupling between services.
14. REST vs gRPC in Microservices
Interview Answer
REST and gRPC are both communication approaches, but they have different strengths.
REST
Uses:
- HTTP
- JSON
Example:
GET /api/orders/123
Response:
{
"id":123,
"status":"Created"
}
Advantages:
- simple
- human readable
- browser friendly
- widely supported
Disadvantages:
- larger messages
- slower serialization
gRPC
Uses:
- HTTP/2
- Protocol Buffers
Example:
service OrderService {
rpc GetOrder(OrderRequest)
returns (OrderResponse);
}
Advantages:
- very fast
- strongly typed
- efficient communication
Disadvantages:
- less browser friendly
- more complex
Typical Usage
External APIs:
Client
|
REST API
Internal microservices:
Service A
|
gRPC
|
Service B
Senior Answer
REST is usually better for public APIs because of simplicity and compatibility. gRPC is often preferred for internal microservice communication because of performance and strong contracts.
15. How would you implement RabbitMQ in microservices?
Interview Answer
RabbitMQ can be used as a message broker to enable asynchronous communication between services.
Architecture:
Order Service
|
Exchange
|
Queue
|
Inventory Service
Example:
Customer creates order:
Order Service
creates:
OrderCreated event
Publishes:
{
"OrderId":123,
"CustomerId":50
}
Inventory Service:
Consumes event:
OrderCreated
|
Reserve Product
Important Features
Acknowledgement
Consumer confirms processing.
Message
|
Process
|
ACK
Retry
If processing fails:
Queue
|
Consumer Failed
|
Retry Queue
Dead Letter Queue
Failed messages go here.
Failed Messages
|
Dead Letter Queue
.NET Example
Common library:
- MassTransit
- RabbitMQ.Client
Senior Answer
RabbitMQ is useful for reliable asynchronous communication. I typically use exchanges, queues, acknowledgements, retries, and dead-letter queues to handle failures.
16. How would you use Kafka in microservices?
Interview Answer
Kafka is used for high-volume event streaming between services.
Architecture:
Producer
|
Kafka Topic
|
Consumers
Example:
Order processing:
Order Service
|
OrderCreated Topic
|
+-------------+-------------+
Inventory Analytics Notification
Kafka Concepts
Topic
A category of events.
Example:
orders.created
Partition
Allows parallel processing.
Example:
Topic
|
+-- Partition 1
|
+-- Partition 2
|
+-- Partition 3
Consumer Group
Multiple consumers share workload.
Use Cases
- event streaming
- analytics
- audit logs
- real-time processing
Senior Answer
Kafka is ideal for high-throughput event-driven systems where multiple services need to consume a stream of business events independently.
17. What is Event-Driven Microservices Architecture?
Interview Answer
Event-driven architecture uses events to notify other services about changes instead of direct service calls.
Traditional approach:
Order Service
|
Payment Service
|
Inventory Service
Tightly coupled.
Event-driven:
Order Service
|
OrderCreated Event
|
Message Broker
|
+-------------+-------------+
Payment Inventory Shipping
Example event:
{
"eventType":"OrderCreated",
"orderId":123
}
Benefits
- loose coupling
- scalability
- easier integration
Challenges
- debugging
- eventual consistency
- event versioning
Senior Answer
Event-driven microservices communicate through business events. This reduces coupling and allows services to evolve independently.
18. Explain the Circuit Breaker Pattern.
Interview Answer
Circuit Breaker prevents repeated calls to a failing service.
Problem:
Order Service
|
Payment Service DOWN
|
Thousands of failed requests
This can overload the system.
Circuit Breaker:
Normal:
Request
|
Payment Service
Failure detected:
OPEN
Requests blocked temporarily
States
Closed
Normal operation.
Request → Service
Open
Calls blocked.
Request → Error Response
Half-Open
Test if service recovered.
Test Request
|
Service
.NET Example
Libraries:
- Polly
- Microsoft.Extensions.Http.Resilience
Senior Answer
Circuit breakers improve system resilience by preventing cascading failures when dependent services are unavailable.
19. Explain Retry Pattern.
Interview Answer
Retry pattern automatically repeats failed operations that may succeed later.
Example:
Temporary network failure:
Request
|
Timeout
|
Retry
|
Success
Good Retry Candidates
Temporary failures:
- network timeout
- service unavailable
- database connection issue
Bad Retry Candidates
Permanent failures:
- invalid request
- authentication failure
Retry Strategies
Immediate Retry
Fail
|
Retry immediately
Exponential Backoff
Example:
Retry 1:
1 second
Retry 2:
5 seconds
Retry 3:
30 seconds
Retry Limit
Example:
Maximum:
3 attempts
Senior Answer
Retry policies should handle temporary failures but must include limits and backoff strategies to avoid increasing system load.
20. Explain Timeout and Fault Handling in Microservices.
Interview Answer
Timeouts prevent a service from waiting indefinitely for another service.
Problem:
Order Service
waiting forever
|
Payment Service
not responding
Solution:
Set timeout:
Payment request
Maximum:
3 seconds
Combined Resilience Strategy
Usually combine:
Timeout
+
Retry
+
Circuit Breaker
+
Fallback
Example:
Order Service
|
Payment Service
|
Timeout after 3 seconds
Retry 2 times
Open Circuit
Return fallback response
Senior Answer
In distributed systems, failures are expected. I use timeouts, retries, circuit breakers, and fallback mechanisms to prevent cascading failures and improve system reliability.
End of Chapter 11 — Microservices
Covered:
✅ Database per Service
✅ Shared Database vs Separate Database
✅ Communication Patterns
✅ REST vs gRPC
✅ RabbitMQ
✅ Kafka
✅ Event-Driven Architecture
✅ Circuit Breaker
✅ Retry Pattern
✅ Timeout Handling
21. What is a Service Mesh?
Interview Answer
A service mesh is an infrastructure layer that manages communication between microservices.
Instead of putting communication logic inside every service, a service mesh uses dedicated proxy components.
Without Service Mesh
Each service handles:
- retries
- authentication
- logging
- encryption
- monitoring
Example:
Order Service
|
|-- Retry logic
|-- Logging
|-- Security
|
Payment Service
Problems:
- duplicated code
- inconsistent behavior
With Service Mesh
Order Service
|
Sidecar Proxy
|
Sidecar Proxy
|
Payment Service
The proxy handles:
- service discovery
- retries
- traffic routing
- encryption
- telemetry
Popular Service Mesh Technologies
- Istio
- Linkerd
- Consul Connect
Example
Traffic management:
User Request
|
Service Mesh
|
90% → Version 1
10% → Version 2
Useful for:
- blue/green deployment
- canary releases
Senior Answer
A service mesh moves cross-cutting communication concerns from application code into infrastructure. It improves observability, security, and traffic management between microservices.
22. What are containers and why are they used in microservices?
Interview Answer
Containers package an application together with its dependencies so it runs consistently across environments.
Traditional deployment:
Developer Machine
Works
Production Server
Fails
Reason:
- different runtime
- missing libraries
- configuration differences
Container approach:
+----------------------+
| Application |
| Runtime |
| Libraries |
| Configuration |
+----------------------+
Container
Benefits
1. Consistency
Same package runs everywhere.
2. Isolation
Each service runs independently.
Example:
Container 1
Order API
Container 2
Payment API
3. Easy Scaling
Create more containers:
Order Service
Container
Container
Container
Popular Technology
- Docker
Senior Answer
Containers provide consistent, isolated environments for microservices and simplify deployment, scaling, and portability across different infrastructures.
23. What is Docker?
Interview Answer
Docker is a platform for building, packaging, and running applications inside containers.
Main Concepts
Image
A template used to create containers.
Example:
ASP.NET Core Application Image
Container
A running instance of an image.
Example:
Image
|
Container
Dockerfile
Defines how to build an image.
Example:
FROM mcr.microsoft.com/dotnet/aspnet:9.0
COPY app .
ENTRYPOINT ["dotnet","OrderApi.dll"]
Example Workflow
Build:
docker build -t order-api .
Run:
docker run order-api
Microservices Example
Docker Container
Order Service
Docker Container
Payment Service
Docker Container
User Service
Senior Answer
Docker allows developers to package microservices with all dependencies into portable containers, making deployments consistent across development, testing, and production environments.
24. What is Kubernetes?
Interview Answer
Kubernetes is a container orchestration platform that automates deployment, scaling, and management of containerized applications.
Without Kubernetes:
Developer manually manages:
- Containers
- Scaling
- Failures
- Networking
With Kubernetes:
Kubernetes Cluster
|
+-----------+-----------+
Pod Pod Pod
Service Service Service
Kubernetes Responsibilities
Deployment
Creates and updates containers.
Scaling
Example:
replicas: 5
Creates:
Order API
Pod 1
Pod 2
Pod 3
Pod 4
Pod 5
Self-Healing
If a container crashes:
Pod Failed
|
Kubernetes
|
Create New Pod
Service Discovery
Allows services to find each other.
Senior Answer
Kubernetes provides automated deployment, scaling, networking, and self-healing capabilities for containerized microservices.
25. What is a Kubernetes Pod?
Interview Answer
A Pod is the smallest deployable unit in Kubernetes. It represents one or more containers running together.
Architecture:
Kubernetes
|
Pod
|
+-------------+
| Container |
| Container |
+-------------+
Usually:
One Microservice
|
One Pod
|
One Container
Example:
id="pod3"
apiVersion: apps/v1
kind: Deployment
spec:
replicas: 3
Creates:
Order API Pod
Order API Pod
Order API Pod
Why not run containers directly?
Kubernetes manages:
- lifecycle
- networking
- scaling
- health checks
Senior Answer
A Pod is Kubernetes' execution unit that hosts one or more containers sharing networking and storage resources.
26. What is Azure Kubernetes Service (AKS)?
Interview Answer
Azure Kubernetes Service (AKS) is Microsoft's managed Kubernetes service.
It provides Kubernetes capabilities without requiring organizations to manage the Kubernetes control plane.
Architecture:
Azure AKS
|
Kubernetes Cluster
|
+------------+------------+
Pod Pod Pod
API Worker Service
AKS Provides
- Kubernetes management
- automatic upgrades
- scaling
- Azure integration
Integration Examples
Azure Container Registry
Store images:
Docker Image
|
Azure Container Registry
|
AKS Deployment
Azure Monitor
Collect:
- logs
- metrics
- alerts
Azure Load Balancer
Expose services externally.
.NET Example Architecture
Angular
|
Azure Front Door
|
AKS
|
ASP.NET Core APIs
|
Azure SQL / Cosmos DB
Senior Answer
AKS provides managed Kubernetes infrastructure in Azure. I use it to deploy containerized microservices with features such as scaling, monitoring, and integration with Azure services.
27. What are AWS ECS and EKS?
Interview Answer
AWS provides two main container orchestration services:
- ECS
- EKS
Amazon ECS
Elastic Container Service.
AWS native container platform.
Architecture:
Docker Container
|
ECS Cluster
|
EC2 or Fargate
Advantages:
- simpler than Kubernetes
- deep AWS integration
- easier operations
Amazon EKS
Elastic Kubernetes Service.
Managed Kubernetes.
Architecture:
Docker Container
|
Kubernetes
|
Amazon EKS
Advantages:
- Kubernetes compatibility
- portable skills
- large ecosystem
ECS vs EKS
ECS | EKS |
AWS proprietary | Kubernetes |
Simpler | More flexible |
Less operational overhead | More control |
AWS-focused | Multi-cloud capable |
Senior Answer
ECS is a simpler AWS-native container orchestration platform, while EKS provides managed Kubernetes. I choose based on operational complexity, portability needs, and team expertise.
28. How do you manage configuration in microservices?
Interview Answer
Configuration should be externalized instead of hard-coded inside applications.
Bad:
id="config1"
string connection =
"Server=myserver";
Better:
Application
|
Configuration Provider
|
Environment Variables
Common Configuration Sources
- environment variables
- configuration servers
- cloud secret stores
Examples:
Azure:
- Azure App Configuration
AWS:
- Parameter Store
Example
Development:
Database=LocalDB
Production:
Database=Azure SQL
Same code, different configuration.
.NET Example
id="config5"
{
"ConnectionStrings": {
"Database": "..."
}
}
Senior Answer
Microservices should keep configuration outside the codebase using environment-specific configuration providers and centralized configuration management.
29. How do you manage secrets in microservices?
Interview Answer
Secrets such as passwords, API keys, and certificates should never be stored in source code.
Bad:
id="secret1"
var password = "MyPassword123";
Better:
Application
|
Secret Store
|
Password/API Key
Secret Management Tools
Azure:
- Azure Key Vault
AWS:
- AWS Secrets Manager
Kubernetes:
- Kubernetes Secrets
Example:
Database connection:
Application
|
Key Vault
|
Connection String
Benefits
- rotation
- auditing
- access control
Senior Answer
I manage secrets using dedicated secret stores such as Azure Key Vault or AWS Secrets Manager, with controlled access and automatic rotation where possible.
30. What are health checks in microservices?
Interview Answer
Health checks allow systems to determine whether a service is running correctly.
Example endpoint:
GET /health
Response:
{
"status":"Healthy"
}
Types
Liveness Check
Question:
"Is the application running?"
Example:
Process alive?
YES
Readiness Check
Question:
"Can the application accept traffic?"
Example:
Database available?
Cache available?
Queue connected?
Kubernetes Example
id="health3"
livenessProbe:
httpGet:
path: /health
Usage
Load balancer:
Healthy Service
|
Receive Traffic
Failed Service
|
Remove From Pool
ASP.NET Core Example
builder.Services
.AddHealthChecks();
Senior Answer
Health checks are essential in microservices because orchestration platforms and load balancers need to know which service instances are healthy and ready to receive traffic.
End of Chapter 11 — Microservices
Covered:
✅ Service Mesh
✅ Containers
✅ Docker
✅ Kubernetes
✅ Pods
✅ Azure AKS
✅ AWS ECS/EKS
✅ Configuration Management
✅ Secrets Management
✅ Health Checks
31. What is distributed tracing?
Interview Answer
Distributed tracing is a technique used to track a single request as it moves through multiple microservices.
In a microservice architecture, one user request may call many services.
Example:
User Request
|
API Gateway
|
Order Service
|
Payment Service
|
Inventory Service
|
Database
Without tracing, it is difficult to know:
- where the request failed
- which service is slow
- how long each service takes
Trace Example
Request:
Trace ID: abc123
API Gateway
50 ms
Order Service
120 ms
Payment Service
800 ms
Inventory Service
40 ms
The slow component is immediately visible.
Important Concepts
Trace
Complete journey of a request.
Span
A single operation inside a trace.
Example:
Trace
|
+-- API Gateway Span
|
+-- Order Service Span
|
+-- Payment Span
Tools
- OpenTelemetry
- Jaeger
- Zipkin
- Application Insights
- AWS X-Ray
Senior Answer
Distributed tracing provides visibility into requests across multiple services by using trace IDs and spans. It is essential for troubleshooting latency and failures in distributed systems.
32. What is OpenTelemetry?
Interview Answer
OpenTelemetry is an open-source standard for collecting telemetry data from applications.
It collects:
- traces
- metrics
- logs
Architecture:
Application
|
OpenTelemetry SDK
|
Collector
|
+-------------+-------------+
Jaeger Grafana Azure Monitor
Example in .NET
ASP.NET Core application:
Request
|
Controller
|
Database Call
|
External API Call
OpenTelemetry captures these operations.
Benefits
- vendor neutral
- standard format
- works with many monitoring platforms
Senior Answer
OpenTelemetry provides a standardized way to instrument applications and collect telemetry data such as traces, metrics, and logs across distributed systems.
33. How should logging be implemented in microservices?
Interview Answer
Microservices should use centralized structured logging.
Bad logging:
Error happened
Not enough information.
Better:
{
"service":"OrderService",
"level":"Error",
"orderId":123,
"message":"Payment failed",
"timestamp":"2026-01-01"
}
Best Practices
Centralized Storage
Instead of:
Service A logs
Service B logs
Service C logs
Use:
Services
|
Log Collector
|
Central Log System
Examples:
- ELK Stack
- OpenSearch
- Splunk
- Azure Monitor
- CloudWatch
Include
Every log should contain:
- timestamp
- service name
- correlation ID
- user/request ID
- severity
Senior Answer
In microservices I use structured centralized logging with correlation IDs so that requests can be tracked across multiple services.
34. What is a correlation ID?
Interview Answer
A correlation ID is a unique identifier attached to a request and passed between services.
It allows tracking one business operation across the entire system.
Example:
User places order:
Request ID:
8f73ab
Flow:
API Gateway
ID: 8f73ab
|
Order Service
ID: 8f73ab
|
Payment Service
ID: 8f73ab
Without correlation ID:
Payment failed
Which order?
Which user?
Unknown.
With correlation ID:
Payment failed
Order: 123
User: 50
Request: 8f73ab
Senior Answer
Correlation IDs provide end-to-end request tracking across microservices and are critical for debugging distributed applications.
35. Explain Blue-Green Deployment.
Interview Answer
Blue-green deployment reduces downtime by maintaining two production environments.
Architecture:
Load Balancer
|
+-----------+-----------+
| |
Blue Green
Current Version New Version
Example:
Current:
Blue
Version 1.0
Deploy:
Green
Version 2.0
Test Green.
Switch traffic:
Users
|
Green
Version 2.0
Advantages
- minimal downtime
- easy rollback
Rollback:
Green has problem
|
Switch back to Blue
Disadvantages
- requires double infrastructure
- higher cost
Senior Answer
Blue-green deployment provides safer releases by deploying a new version in a separate environment and switching traffic only after validation.
36. Explain Canary Deployment.
Interview Answer
Canary deployment releases a new version to a small percentage of users before full rollout.
Example:
Users
|
Load Balancer
90%
Version 1
10%
Version 2
Monitor:
- errors
- performance
- user feedback
If successful:
100%
Version 2
Advantages
- reduces risk
- detects production issues early
Common Tools
- Kubernetes
- Istio
- Azure DevOps
- AWS CodeDeploy
Senior Answer
Canary deployment gradually introduces changes to production by exposing a small user group first, reducing the impact of potential failures.
37. How do you implement CI/CD for microservices?
Interview Answer
Each microservice should have its own automated build and deployment pipeline.
Architecture:
Developer
|
Git Repository
|
CI Pipeline
|
Build Docker Image
|
Container Registry
|
Deploy
|
Kubernetes / Cloud
Pipeline Steps
1. Build
Compile application.
Example:
dotnet build
2. Test
Run:
3. Package
Create container:
docker build
4. Deploy
Example:
Docker Image
|
AKS Deployment
Tools
Azure:
- Azure DevOps
- GitHub Actions
AWS:
- CodePipeline
- CodeBuild
Senior Answer
In microservices, CI/CD pipelines are usually independent per service, allowing teams to build, test, and deploy services independently.
38. How do you test microservices?
Interview Answer
Testing microservices requires multiple levels of testing.
1. Unit Testing
Tests individual components.
Example:
Order Calculation
Input
Output
Tools:
- xUnit
- NUnit
2. Integration Testing
Tests service interaction.
Example:
Order Service
|
Database
3. Contract Testing
Ensures APIs between services remain compatible.
Example:
Order Service
expects:
Payment API v1
4. End-to-End Testing
Tests complete user scenarios.
Example:
Create Order
|
Pay
|
Ship
Senior Answer
Microservices require layered testing including unit tests, integration tests, contract tests, and end-to-end tests to validate both individual services and communication between them.
39. What security patterns are used in microservices?
Interview Answer
Microservices require security at multiple levels.
Authentication
Usually:
- OAuth 2.0
- OpenID Connect
- JWT
Flow:
User
|
Identity Provider
|
JWT Token
|
API Gateway
Authorization
Controls permissions.
Example:
Admin
Create/Delete
User
Read Only
Service-to-Service Security
Use:
- mutual TLS
- service identities
Secrets
Store in:
- Azure Key Vault
- AWS Secrets Manager
Network Security
Use:
- private networks
- firewall rules
- security groups
Senior Answer
Microservices security requires authentication, authorization, encrypted communication, secure secret storage, and network isolation.
40. Describe a complete microservices architecture for an enterprise system.
Interview Answer
A typical enterprise architecture might look like this:
Users
|
API Gateway
|
+-----------+-----------+
| | |
User Order Payment
Service Service Service
| | |
DB DB DB
|
Message Broker
|
+-----------+-----------+
Inventory Notification Audit
|
Monitoring Platform
Components
API Gateway
Handles:
- routing
- authentication
- throttling
Microservices
Each service:
- owns business logic
- owns data
- deploys independently
Message Broker
Handles:
- asynchronous events
- integration
Examples:
- RabbitMQ
- Kafka
- Azure Service Bus
Observability
Includes:
- logs
- metrics
- tracing
Deployment
Usually:
Docker
|
Kubernetes
|
Cloud Platform
Senior Answer
A production microservices architecture combines independently deployable services, API gateway, asynchronous messaging, separate data ownership, container orchestration, security, and observability. The goal is scalability, resilience, and maintainability.
Chapter 11 — Microservices Completed ✅
Total:
40 Microservices Interview Questions
Covered:
✅ Microservices fundamentals
✅ DDD
✅ Service boundaries
✅ API Gateway
✅ Service Discovery
✅ Database patterns
✅ REST/gRPC
✅ RabbitMQ
✅ Kafka
✅ Event-driven architecture
✅ Resilience patterns
✅ Docker
✅ Kubernetes
✅ AKS/EKS
✅ Configuration
✅ Secrets
✅ Health checks
✅ Observability
✅ CI/CD
✅ Security
✅ Enterprise architecture