What Happens if One Microservice Fails?
In Microservices Architecture, applications are divided into multiple independent services.
Each microservice handles a specific business functionality such as:
- Auth Service
- Payment Service
- Course Service
- Notification Service
- Order Service
Since services communicate with each other over the network, failures can occur at any time.
Understanding what happens when one microservice fails is very important for designing reliable and scalable distributed systems.
Simple Understanding
Imagine a shopping mall.
Suppose:
- Food court closes temporarily
- Movie theater still works
- Clothing stores still work
One department failure does not shut down the entire mall.
Similarly, in Microservices Architecture:
- One microservice failure ideally should not crash the whole application
What Causes Microservice Failures?
Microservices may fail because of:
- Server crashes
- Database failures
- Memory issues
- Network failures
- Code bugs
- Heavy traffic
- Dependency failures
- Timeout issues
Example Microservices Architecture
API Gateway
|
------------------------------------------------------
| | | |
v v v v
Auth Service Payment Service Course Service Notification Service
Scenario: Payment Service Fails
Suppose Payment Service crashes.
Possible Effects
- Payments may fail
- Order completion may fail
- Other independent services may continue working
What Happens Without Proper Failure Handling?
Suppose Order Service directly depends on Payment Service synchronously.
Order Service ---> Payment Service
If Payment Service fails:
- Order Service waits indefinitely
- User requests become slow
- System performance decreases
This is called:
Cascade Failure
What is Cascade Failure?
Cascade failure occurs when failure in one microservice affects multiple dependent services.
Cascade Failure Example
Client | v Order Service | v Payment Service (FAILED) | v Notification Service
If Payment Service becomes unavailable:
- Order processing stops
- Notifications fail
- Users experience errors
How Microservices Handle Failures
Modern microservices use several fault-tolerance techniques:
- Circuit Breaker
- Retries
- Fallback Mechanisms
- Timeouts
- Load Balancing
- Auto Scaling
- Message Queues
- Event-Driven Architecture
1. Circuit Breaker Pattern
Circuit Breaker prevents continuous requests to failed services.
Example
Order Service
|
X
Payment Service Failed
Circuit breaker immediately stops requests temporarily.
This prevents system overload.
Circuit Breaker States
1. Closed State
Requests work normally.
2. Open State
Requests stop because service is failing.
3. Half-Open State
System tests whether service recovered.
Spring Boot Resilience4j Example
@CircuitBreaker(
name = "paymentService",
fallbackMethod = "fallbackPayment"
)
public String processPayment() {
return paymentClient.makePayment();
}
Fallback Method
public String fallbackPayment(Exception ex) {
return "Payment Service Temporarily Unavailable";
}
2. Retry Mechanism
Temporary failures may recover automatically.
Retry mechanism resends requests after failures.
Example
Attempt 1 -> Failed Attempt 2 -> Failed Attempt 3 -> Success
Spring Retry Example
@Retry(name = "paymentRetry")
public String makePayment() {
return paymentClient.process();
}
3. Timeout Handling
Services should not wait indefinitely for responses.
Example
Wait Maximum 5 Seconds
If timeout exceeds:
- Request fails gracefully
Feign Client Timeout Example
feign:
client:
config:
default:
connectTimeout: 5000
readTimeout: 5000
4. Fallback Mechanism
Fallback provides alternative responses during failures.
Example
Payment Service Down
|
v
Return Cached Response
5. Load Balancing
Microservices usually run multiple instances.
Example
Payment Service Instance 1 Payment Service Instance 2 Payment Service Instance 3
If one instance fails:
- Traffic redirects to healthy instances
6. Auto Scaling
Cloud platforms automatically create additional service instances during high traffic.
7. Event-Driven Architecture
Asynchronous communication reduces direct dependency.
Without Event-Driven Architecture
Order Service ---> Payment Service
With Kafka
Order Service
|
v
Kafka Event
|
v
Payment Service Processes Later
Order Service does not block immediately.
8. Message Queues
Message queues store requests temporarily if services fail.
Example
Order Created Event
|
v
Kafka Queue
When Payment Service recovers:
- Pending events are processed
9. Health Checks
Systems continuously monitor service health.
Spring Boot Actuator Example
/actuator/health
If service becomes unhealthy:
- Traffic routing stops
10. Container Restarting
Docker and Kubernetes automatically restart failed containers.
Kubernetes Self-Healing Example
Payment Pod Crashes
|
v
Kubernetes Restarts Pod
Real-Time Failure Example
Suppose an e-commerce platform contains:
- Order Service
- Payment Service
- Inventory Service
- Notification Service
Scenario: Payment Service Failure
What Happens?
- Orders may remain pending
- Inventory updates may pause
- Notifications may delay
How System Recovers
- Circuit breaker stops excessive requests
- Kafka stores pending events
- Kubernetes restarts failed containers
- Retries happen automatically
- Load balancer redirects traffic
Failure Isolation in Microservices
One major advantage of microservices is:
Failure isolation
Failure in one service usually does not crash the entire system.
Monolith vs Microservices Failure
| Feature | Monolith | Microservices |
|---|---|---|
| Failure Impact | Entire system may crash | Specific service affected |
| Scalability | Whole application scaling | Individual service scaling |
| Recovery | Slower | Faster |
| Isolation | Poor | Better |
Tools Used for Fault Tolerance
| Tool | Purpose |
|---|---|
| Resilience4j | Circuit breaker and retries |
| Kafka | Asynchronous messaging |
| Kubernetes | Container orchestration |
| Prometheus | Monitoring |
| Grafana | Visualization and alerts |
Best Practices to Handle Microservice Failures
- Use Circuit Breaker pattern
- Implement retries carefully
- Use asynchronous messaging
- Enable health checks
- Use load balancing
- Implement monitoring and alerts
- Use container orchestration tools
Real-Time Company Example
Netflix uses advanced fault-tolerance mechanisms in microservices.
Netflix systems:
- Automatically detect failures
- Reroute traffic
- Use circuit breakers
- Scale services dynamically
This helps Netflix maintain high availability globally.
Interview Ready Answer
If one microservice fails, only the functionality handled by that specific service may be affected, while other independent services continue working. However, if proper fault-tolerance mechanisms are not implemented, failures can propagate and cause cascade failures across the system. Microservices architecture handles failures using techniques such as Circuit Breaker, Retry Mechanisms, Fallback Responses, Timeouts, Load Balancing, Event-Driven Architecture, Message Queues, Health Checks, and Kubernetes self-healing. These mechanisms improve fault isolation, scalability, and system reliability.
Frequently Asked Questions
Can one microservice failure crash the entire application?
Ideally no, because microservices are independently isolated.
What is cascade failure?
Cascade failure occurs when failure in one service affects multiple dependent services.
What is Circuit Breaker?
Circuit Breaker stops requests temporarily to failed services to prevent overload.
How does Kubernetes help during failures?
Kubernetes automatically restarts failed containers and reroutes traffic.
Why is Kafka useful during service failures?
Kafka stores events temporarily so services can process them after recovery.